import java.math.BigDecimal;
public class BigDecimalCheckUtils {
/**
* 判断string是否是BigDecimal且大于0
*
* @param str 字符串
* @return 结果
*/
public static boolean isPositiveBigDecimal(String str) {
try {
BigDecimal bigDecimal = new BigDecimal(str);
return bigDecimal.compareTo(BigDecimal.ZERO) > 0;
} catch (NumberFormatException e) {
return false;
}
}
public static void main(String[] args) {
String test1 = "123.45";
String test2 = "-0.99";
String test3 = "0";
String test4 = "abc";
System.out.println(isPositiveBigDecimal(test1)); // true
System.out.println(isPositiveBigDecimal(test2)); // false
System.out.println(isPositiveBigDecimal(test3)); // false
System.out.println(isPositiveBigDecimal(test4)); // false
}
}
08-16
1075
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)