修复umberUtil.parseNumber对+解析问题

This commit is contained in:
Looly 2023-06-01 18:02:36 +08:00
parent ac53cec860
commit 0ad26a61ed
3 changed files with 13 additions and 1 deletions

View File

@ -2,7 +2,7 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.8.20(2023-05-31)
# 5.8.20(2023-06-01)
### 🐣新特性
* 【core 】 UrlQuery增加setStrict方法区分是否严格模式issue#I78PB1@Gitee
@ -10,6 +10,7 @@
### 🐞Bug修复
* 【core 】 修复TreeUtil.getParentsName()获取到的路径集合中存在值为null的路径名称问题issue#I795IN@Gitee
* 【core 】 修复umberUtil.parseNumber对+解析问题issue#I79VS7@Gitee
-------------------------------------------------------------------------------------------------------------
# 5.8.19(2023-05-27)

View File

@ -2601,6 +2601,9 @@ public class NumberUtil {
if (StrUtil.startWithIgnoreCase(numberStr, "0x")) {
// 0x04表示16进制数
return Long.parseLong(numberStr.substring(2), 16);
}else if(StrUtil.startWith(numberStr, '+')){
// issue#I79VS7
numberStr = StrUtil.subSuf(numberStr, 1);
}
try {

View File

@ -600,4 +600,12 @@ public class NumberUtilTest {
Assert.assertFalse(NumberUtil.isIn(new BigDecimal("0.23"),new BigDecimal("0.12"),new BigDecimal("0.22")));
Assert.assertTrue(NumberUtil.isIn(new BigDecimal("-0.12"),new BigDecimal("-0.3"),new BigDecimal("0")));
}
@Test
public void issueI79VS7Test() {
final String value = "+0.003";
if(NumberUtil.isNumber(value)) {
Assert.assertEquals(0.003, NumberUtil.parseNumber(value).doubleValue(), 0);
}
}
}