How I can get a decimal number from string to use it for calculations and math ? using android studio ( Java )
String a = "0.1234"
String b = "0.4321"
total = a * b
How I can get a decimal number from string to use it for calculations and math ? using android studio ( Java )
String a = "0.1234"
String b = "0.4321"
total = a * b
You can do as Arju said or alternative is to parseFloat
float floatA = Float.parseFloat(a);
float floatB = Float.parseFloat(b);
float total = floatA*floatB;
This will do:
String a = "0.1234"
float aFloat = Float.parseFloat(a);
String b = "0.4321"
float bFloat = Float.parseFloat(b);
total = aFloat * bFloat
This might throw a NumberFormatException
, so you will have to put it in a try block.