当前位置: 代码迷 >> Java相关 >> 判断数目字为大于0小于等于1000000,整数小数都可但小数最多两位
  详细解决方案

判断数目字为大于0小于等于1000000,整数小数都可但小数最多两位

热度:5009   发布时间:2013-02-25 21:44:34.0
判断数字为大于0小于等于1000000,整数小数都可但小数最多两位
判断数字为大于0小于等于1000000,整数小数都可但小数最多两位

------解决方案--------------------------------------------------------
Java code
public static void main(String[] args) {        String str = "1";        System.out.println(checkyonghuxiaoying(str));        str = "1000000";        System.out.println(checkyonghuxiaoying(str));        str = "999999.99";        System.out.println(checkyonghuxiaoying(str));        str = "0";        System.out.println(checkyonghuxiaoying(str));        str = "999999.999";        System.out.println(checkyonghuxiaoying(str));        str = "1000001";        System.out.println(checkyonghuxiaoying(str));    }        public static boolean checkyonghuxiaoying(String value) {        boolean ret = true;        try {            double d = Double.parseDouble(value);            if (d <= 0 || d > 1000000) {                ret = false;                }                    } catch (Exception e) {            ret = false;        }        if (ret) {            int index = value.lastIndexOf(".");            if (index != -1) {                if (value.substring(index + 1).length() > 2) {                    ret = false;                }            }        }        return ret;    }