android:inputType="numberDecimal"
输入限制了这个,不用判断小数点个数了。下面是判断过得
String money = et_budget.getText().toString(); String dot = "."; int count = money.length() - money.replace(dot, "").length(); if (money != null && money.length() > 0){//不能为空 if(money.startsWith(".")){//不能以小数点开头 ToastUtils.showToast(ReleaseTaskActivity.this, "请输入正确预算"); }else if (count > 1) {//小数点不能多于一位 ToastUtils.showToast(ReleaseTaskActivity.this, "请输入正确预算"); }else if (Double.parseDouble(money) <= 0) { ToastUtils.showToast(ReleaseTaskActivity.this, "预算必须大于0"); } else { Intent intent = new Intent(); Bundle bundle = new Bundle(); bundle.putString("price", money); intent.putExtras(bundle); setResult(RESULT_OK, intent); finish(); } } else { ToastUtils.showToast(ReleaseTaskActivity.this, "预算不能为空"); }