I
I
Ivan the Terrible2015-10-13 20:03:52
Java
Ivan the Terrible, 2015-10-13 20:03:52

How to get the integer part of a real number?

There is a real number.
For example :
double x = 23.35;
How to get its integer part ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
AVKor, 2015-10-13
@AVKor

int i = x.intValue();

L
LittleFatNinja, 2015-10-13
@LittleFatNinja

or int integralPart = (int) x;
long integralPart = (long) x;

A
Aska2790, 2020-07-29
@Aska2790

double value = 23.35
String[] a = String.valueOf(value).split("[.]");
int _int = Integer.parseInt(a[0]);
int _frac = Integer.parseInt(a[1])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question