复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55package CommonUtil; import java.math.BigDecimal; import java.util.regex.Pattern; /** * 处理基本数据类型转换的工具类 (字符串类型转换为BigDecimal金额、int、Double) */ public class DataTypeUtil { /** * 字符串转换为BigDecimal金额类型 */ public static BigDecimal getBigDecimal(String s) { if (s != null && Pattern.matches("^\d+\.??\d+$", s)) { try { return new BigDecimal(s); } catch (Exception e) { e.printStackTrace(); } } return null; } /** * 字符串转换为int类型 */ public static int parseInt(String s) { if (s != null && Pattern.matches("^\d*$", s)) { try { return Integer.parseInt(s); } catch (Exception e) { e.printStackTrace(); } } return 0; } /** * 字符串转换为转换Double型 */ public static Double parseDouble(String s) { if (s != null && Pattern.matches( "^[-+]?(/d+(/./d*)?|/./d+)([eE]([-+]?([012]?/d{1,2}|30[0-7])|-3([01]?[4-9]|[012]?[0-3])))?[dD]?$", s)) { try { return Double.parseDouble(s); } catch (Exception e) { e.printStackTrace(); return null; } } return null; } }
最后
以上就是怕孤单心锁最近收集整理的关于处理基本数据类型转换的工具类 (字符串类型转换为BigDecimal金额、int、Double)的全部内容,更多相关处理基本数据类型转换的工具类内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复