/**
* param 参数
* places 位数
* checkStringDecimals 校验字符串小数位数
*/
private void checkStringDecimals(String param, int places) {
if (param.contains(".")) {
int i = param.indexOf(".");
int length = param.length() - i;
if (length > places + 1) {
throw new IllegalArgumentException("参数" + param + "不合法");
}
}
}
思路很简单,字符串中如果包含".",就看他是在第几位,然后比较。