Arif YILMAZ Arif YILMAZ - 1 year ago 168
Android Question

convert string to float in android

I am trying to convert string to float but I couldnt succeed.

here is my code

float f1 = Float.parseFloat("1,9698");

the error it gives is

Invalid float "1,9698";

why is it doing this? it is a valid float

Answer Source

You are using a comma when you should be using a period

float f1 = Float.parseFloat("1.9698");

That should work.

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