【问题标题】:how to set the number format for an EditText如何设置 EditText 的数字格式
【发布时间】:2012-07-10 09:03:45
【问题描述】:

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

我该怎么做?

这是在安卓中

【问题讨论】:

    标签: android numbers format


    【解决方案1】:

    你可以使用DecimalFormat

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

    您将在EditText 中得到25.0 的结果

    【讨论】:

      【解决方案2】:

      您可以在 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" >
      

      【讨论】:

        猜你喜欢
        • 2016-10-15
        • 2015-09-20
        • 2011-11-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多