user3669712 user3669712 - 1 year ago 79
Java Question

Concatenate two integer to get a float in Java

I have two integer values as below

int fb = (int) (duration.toMinutes() / 60.0);
int fb1 = (int) (duration.toMinutes() % 60.0);

I want a float variable like below

float fb2 = fb.fb1

Example :If I have two int values as fb = 3 and fb1=30 i need float fb2= 3.30

Help me how to achieve the above in java with minimal code.

Answer Source

Try Float.parseFloat(), like this:

float fb2 = Float.parseFloat(fb + "." + fb1);

You could also use Float.valueOf() combined with String.valueOf(), like this:

float fb2 = java.lang.Float.valueOf(String.valueOf(fb) +"."+ 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download