EditText 保留两位小数

               

布局XML文件:

android:inputType="numberDecimal"

源代码:

editMoney = (EditText) findViewById(R.id.EditMoney);
  editMoney.addTextChangedListener(new TextWatcher()
  {
      public void afterTextChanged(Editable edt)
      {
          String temp = edt.toString();
          int posDot = temp.indexOf(".");
          if (posDot <= 0) return;
          if (temp.length() - posDot - 1 > 2)
          {
              edt.delete(posDot + 3, posDot + 4);
          }
      }

      public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}

      public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}
  });

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自blog.csdn.net/gfuugff/article/details/86666211