Zeratops Zeratops - 1 year ago 137
Android Question

split float in Java Android

I have a number like 2.75. I want to split this number into two other floats. Here is an example of what I am searching for:

value = 2.75
value2 = 2.0
value3 = 0.75

I need them in my algorithm, so how could I implement this? I found
but it returns string. I need floats or integer at least.

Answer Source

You can also try this

double value = 2.75;
double fraction=value%1;//Give you 0.75 as remainder 
int integer=(int)value;//give you 2 fraction part will be removed

NOTE: As result may very in fraction due to use of double.You better use

float fraction=(float) (value%1);

if fractional part is big.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download