Вопрос

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();
Это было полезно?

Решение

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

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top