提问者:小点点

如何设置EditText的数字格式


我希望数字在我的EditText中显示,最多1位小数,没有前导零,例如25.0不像025.0

我该怎么做?

这是在Android系统中


共2个答案

匿名用户

您可以使用< code>DecimalFormat

DecimalFormat format = new DecimalFormat("##.#");
String formattedText = format.format(025.0);
editText.setText(formattedText);

您将在编辑文本中获得结果为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" >