I am trying to separate a double into the integer and decimal parts
So for example, the number 24.4 should be separated into 24 and 4.
int integer =
Depending on the number of decimal digits, you could use this method:
double number = 24.4;
int integer = (int)number;
double decimal = (10 * number - 10 * integer)/10;
System.out.println(decimal);
Explanation: Remove the decimal points, do the subtraction, and finally return the decimal point back to its original location!
You can do this:
(val - val.longValue()) * 100
use 1000 to get 3 fractions:
for example:
(1.2445 - 1) * 100 = 0.244
First find the number the digits after the decimal point, and with that much number of 10's you have to multiply. eg: x=26.78621 then multiply by 100000[ here you can't multiply like x*10, again x*10 so on (5 times), the 1st time you multiply with 10, it will give you 267.862199999..] After multiplication subtract 2600000 from the result. here is a link of your answer which i have code it. https://stackoverflow.com/a/18517555/2508414
double number = 20.57;
Double.valueOf(String.valueOf(number)).intValue()
float number = (float) 22.45;
int integer = (int)number;
double decimal = number-integer;
System.out.println(integer + "decimal" + decimal);