【发布时间】:2012-07-10 09:03:45
【问题描述】:
我希望在我的 EditText 中显示的数字最多保留 1 位小数,没有前导零,例如25.0 不像 025.0
我该怎么做?
这是在安卓中
【问题讨论】:
我希望在我的 EditText 中显示的数字最多保留 1 位小数,没有前导零,例如25.0 不像 025.0
我该怎么做?
这是在安卓中
【问题讨论】:
你可以使用DecimalFormat
DecimalFormat format = new DecimalFormat("##.#");
String formattedText = format.format(025.0);
editText.setText(formattedText);
您将在EditText 中得到25.0 的结果
【讨论】:
您可以在 xml 文件中设置它。喜欢
<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" >
【讨论】: