Arif YILMAZ Arif YILMAZ - 17 days ago 6
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

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

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

That should work.