In my android app, I have an EditText in which the user enters a decimal which can be as long as the user wants. It can be a number like 25, 54.77, 23.7, 7.88, etc. In the same activity, I have a textView which reads the input into the EditText and displays the decimal but only till the first decimal digit. For e.g. if the user enters: 25 should be displayed as 25, 54.77 as 54.7, 23.7 as 23.7, 7.88 as 7.8. How can I achieve this? I tried using the following code but it didn’t work:
NumberFormat df = DecimalFormat.getInstance();
df.setMinimumFractionDigits(0);
df.setMaximumFractionDigits(1);
df.format(EditTextNumber);
Use
String.format:you can use
DecimalFormattoo: