edittext 在输入价格时限定输入的位数不大于1000000且可以输入两位小数,第一位不能输入.

来源:互联网 发布:珠海seo招聘 编辑:程序博客网 时间:2024/06/11 20:12
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);//删除小数点后的第三位    }
0 0
原创粉丝点击