用于校验bigdecimal的正则表达式

用于校验bigdecimal的正则表达式

class c1 {
    public static void main(String[] args) {

        BigDecimal bigDecimal = new BigDecimal("000.0000000000000000000000010000000");
        System.out.println(bigDecimal.toString());//1.0000000E-24
        System.out.println(bigDecimal.toPlainString());//0.0000000000000000000000010000000
        System.out.println(bigDecimal.stripTrailingZeros().toString());//1E-24
        System.out.println(bigDecimal.stripTrailingZeros().toPlainString());//0.000000000000000000000001
        // 32位 其中小数点8位
        String ss = "-?[1-9]\\d{0,23}(\\.\\d{1,8})?$|-?0(\\.\\d{1,8})?$";
        // 井号是结束的意思 问号表示出现0次或者一次
        Pattern compile = Pattern.compile(ss);
        Matcher matcher = compile.matcher("0.112");//true
        Matcher matcher2 = compile.matcher("-1.112");//true
        Matcher matcher3 = compile.matcher("0.112");//true
        Matcher matcher4 = compile.matcher("10.112");//true
        Matcher matcher5 = compile.matcher("1.1121.112");//false
        Matcher matcher6 = compile.matcher("111111111111111111111111.11111111");//true
        Matcher matcher7 = compile.matcher("0");//true
        Matcher matcher8 = compile.matcher("0.0");//true
        Matcher matcher9 = compile.matcher("000.9");//false
        System.out.println(matcher.matches());
        System.out.println(matcher2.matches());
        System.out.println(matcher3.matches());
        System.out.println(matcher4.matches());
        System.out.println(matcher5.matches());
        System.out.println(matcher6.matches());
        System.out.println(matcher7.matches());
        System.out.println(matcher8.matches());
        System.out.println(matcher9.matches());


    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值