I am developing an app in which i have to get the float part in terms of integer value.
for example if my number is 153.12324
then output should be 12324
.I tried this way but it works wrong some time.
What's the problem in this or is there a better way to do this ?
there is a double value in d
double d =any_double_value;
String[] splitter = String.valueOf(d).split("\\.");
splitter[0].length(); // Before Decimal Count
int count = splitter[1].length();
int integerpart = (int) calcResult;
double floatpart = calcResult - integerpart;
while (count!=0)
{
floatpart=floatpart*10;
count--;
}
int floatpartinInt=(int)floatpart;
this works wrong only in some cases(it gives 1 number less, like if answer is 124 it gives 123) and in cases where answer is long double no like 3.333333333 (10/3)