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();
Était-ce utile?

La solution

String temp = tv.getText().toString().replace.(",","."); tv.setText(""+temp);

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top