一句话,BigDecimal转为字符串,匹配正则表达式,so easy;
不废话,代码:
import java.math.BigDecimal; import java.util.regex.Pattern; public class test { public static void main(String[] args) { BigDecimal a = new BigDecimal(1000); BigDecimal b = new BigDecimal(99.999); String integerStr = a+"" ; String doubleStr = b+""; System.out.println(Pattern.matches("\d+", integerStr));//判断是否可转换为Integer(short即long可以发散,就是改正则) System.out.println(Pattern.matches("\d+\.+", integerStr));//判断是否可转换为Double } }