山一程--软件--数据转换

目的:处理数据的转换


referene

1. java.common.lang  util   

2. express pattern


1. common.lang

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.12.0</version>
</dependency>

版本 3.5 以上的用

NumberUtils.isCreatable  /  StringUtils.isNumber

-----------------------------------------------------------------------------------------------------------------------------------------------

1.use StringUtils.isNumericSpace which returns true or empty strings and ignors internal spaces in the string.

2.another way is to use NumberUtils.isParsable which basically checks the number is parsable according to Java.

-----------------------------------------------------------------------------------------------------------------------------------------------

实测结果

以上方法对于西式数据千分位表示法的数据 

"3,220.81" 未能准确识别.

StringUtils.isNumeric(str) : 全部由数字组成或返回 true.

StringUtils.isNumberSpace(str): 只由数字和空格组成.

 

StringUtils.isAplhanumericSpace (String str): 只由字母数字和空格.
StringUtils.isAlphaspace(String str): 全部由字母或空格组成 返回 true.
StringUtils.isAplha(str)
NumberUtils.isDigits(str): 是否为整数。

BigDecimal  无法处理 带千分位的数字字符串表示,会报错

处理方式 NumberFormat 去掉千分位

 divide  被除數,小數點后保留 位數,取捨

 

posted @ 2023-07-21 10:15  君子之行  阅读(21)  评论(0)    收藏  举报