问题
I want the number being displayed in my EditText upto 1 decimal place with no leading zeroes e.g. 25.0 not like 025.0
how can i do this?
this is in android
回答1:
You can use DecimalFormat
DecimalFormat format = new DecimalFormat("##.#");
String formattedText = format.format(025.0);
editText.setText(formattedText);
You will get result in EditText
as 25.0
回答2:
you can set it in xml file. Like
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageView1"
android:layout_below="@+id/imageView1"
android:layout_marginLeft="20dp"
android:layout_marginTop="54dp"
android:ems="10"
android:inputType="numberDecimal" >
来源:https://stackoverflow.com/questions/11409979/how-to-set-the-number-format-for-an-edittext