public void afterTextChanged(Editable s) { String temp = s.toString(); int posDot = temp.indexOf(".");//返回指定字符在此字符串中第一次出现处的索引 if (posDot <= 0) {//不包含小数点 if (temp.length() <= 6 ) { if(!temp.substring(0).equals(".")){ if(temp.length() > 1){ if(temp.substring(0).equals("0")){ if(!temp.substring(1).equals("0")){ return; }else { s.delete(0,1); } return;//小于五位数直接返回 }else { return; } }else { return; } }else { s.delete(0,1); } } else { if(!temp.substring(0).equals(".")){ s.delete(6, 7);//大于五位数就删掉第六位(只会保留五位) }else { s.delete(0,1); } return; } } if (temp.length() - posDot - 1 > 2)//如果包含小数点 { s.delete(posDot + 3, posDot + 4);//删除小数点后的第三位 }