Save only the whole part of a float or double in Java? [closed]

-1

I would like to know if there is any method to save the whole part of a float type variable in another Integer variable. I've been looking and I have not found anything, I'm there with the doubt. Greetings!

    
asked by Javi Ortiz 21.04.2017 в 05:56
source

1 answer

6

It is enough that you make a casting of the variable to its corresponding type of data in this case be an int or a long

Example

Float a whole

float real = 14.444f;
int entero = (int)real;

Double to whole

double real = 14.444;
int entero = (int)real;

The same applies for the long

    
answered by 21.04.2017 в 06:19