String temp = tv.getText().toString().replace.(",","."); tv.setText(""+temp);
Android NumberFormat Currency
题
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();
解决方案
其他提示
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
不隶属于 StackOverflow