-1

Can you tell me how to achieve this in android:

Transform a String into a float as in:

String temp="1,000,00"

to

float f=100f

I had already gone through links. Getting this exception :

java.lang.NumberFormatException: Invalid float: ""

Sagar Gangawane
  • 1,985
  • 1
  • 12
  • 22

3 Answers3

3

Have you tried like this:

String s = "100";
float f = Float.parseFloat(s);

and make sure that the String you are parsing is indeed a float and is not null or empty

Nongthonbam Tonthoi
  • 12,667
  • 7
  • 37
  • 64
0

You should be using the Float class's parseFloat method.

It sounds like the problem is with the actual string you are using though - can you post that?

Martin Milan
  • 6,346
  • 2
  • 32
  • 44
0

Use the Float class.

// String to Float 
float temp = Float.parseFloat("100f");

// Float to String: 
String str = Float.toString(100.0f);
Diyarbakir
  • 1,999
  • 18
  • 36