String temp = tv.getText().toString().replace.(",","."); tv.setText(""+temp);
Android NumberFormat Currency
Question
How can I convert the Currency to float? for example € 10,10 to 10.10
I tried it but no good.
float f = Float.valueOf(tv.getText().toString()).floatValue();
Solution
OTHER TIPS
Of course it's no good, because you have to remove the character of the currency first (€, $...). You could use String.replace("€", "")
for example, and then Float.parseFloat(yourString)
.
One suggestion, do not allow the user to type in any character but numbers so parsing does not fail
In the EditText for input
android:inputType="numberDecimal"
http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow