判断BigDecimal是否可以转为Integer或Double
2024-10-14 04:44:38
一句话,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
}
}
最新文章
- winform窗体控件(全)
- Android using Accelerometer
- 深入理解AOP
- YTU 3022: 完全二叉树(1)
- 在 Tomcat 中设置 JDBCRealm
- IB_DESIGNABLE的使用
- 利用反射动态构成sql语句
- 【Andord真】SlideMenu+ViewPagerIndictor双滑动边栏+滑动导航条
- USACO 3.4 Raucous Rockers
- apicloud教程1 (转载)
- 笔记:Spring Cloud Hystrix Command属性
- mongoVUE破解与配置、Mongodb数据库安装
- mysql远程访问1045的问题解决
- 什么是arp协议?
- HTML特殊符号(字符实体)大全
- codeforces 13EE. Holes(分块&;amp;动态树)
- bootstrapTable使用场景及方式
- AtCoder Beginner Contest 120 解题报告
- Vue.set全局操作
- MySQL篇,第二章:数据库知识2