Entering decimal values ​​in Edittext?

I have text editing. I want to enter decimal values ​​into it.

that is, when I enter the first number. it should be something like this: .01

then I enter the second number. it should be like this: .12

then for the third. it should be like this: 1.23

it will go like this ... how to implement this scenario. Any idea?

+3
source share
2 answers

You must add a TextWatcher to the EditText. This will notify you when the text changes.

When you know that the text has changed, you can run it through DecimalFormat:

DecimalFormat decimalFormat = new DecimalFormat();
decimalFormat.setDecimalSeparatorAlwaysShown(true);
decimalFormat.setMaximumFractionDigits(2);
+4
source

TextWatcher, , . . SO TextWatcher.

+1

Source: https://habr.com/ru/post/1789055/


All Articles