日期:2014-05-20 浏览次数:20838 次
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;
}