mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
fix bug
This commit is contained in:
parent
bfa130b564
commit
c72ff2c292
@ -19,6 +19,7 @@
|
||||
* 【core 】 修复CAR_VIN正则(pr#624@Gitee)
|
||||
* 【db 】 修复count查询别名问题(issue#I590YB@Gitee)
|
||||
* 【json 】 修复json中byte[]无法转换问题(issue#I59LW4@Gitee)
|
||||
* 【core 】 修复NumberUtil.isXXX未判空问题(issue#2350@Github)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -1238,10 +1238,12 @@ public class NumberUtil {
|
||||
* @return 是否为整数
|
||||
*/
|
||||
public static boolean isInteger(String s) {
|
||||
try {
|
||||
Integer.parseInt(s);
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
if(StrUtil.isNotBlank(s)) {
|
||||
try {
|
||||
Integer.parseInt(s);
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -1255,10 +1257,12 @@ public class NumberUtil {
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public static boolean isLong(String s) {
|
||||
try {
|
||||
Long.parseLong(s);
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
if(StrUtil.isNotBlank(s)) {
|
||||
try {
|
||||
Long.parseLong(s);
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -1270,11 +1274,13 @@ public class NumberUtil {
|
||||
* @return 是否为{@link Double}类型
|
||||
*/
|
||||
public static boolean isDouble(String s) {
|
||||
try {
|
||||
Double.parseDouble(s);
|
||||
return s.contains(".");
|
||||
} catch (NumberFormatException ignore) {
|
||||
// ignore
|
||||
if(StrUtil.isNotBlank(s)) {
|
||||
try {
|
||||
Double.parseDouble(s);
|
||||
return s.contains(".");
|
||||
} catch (NumberFormatException ignore) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -444,4 +444,11 @@ public class NumberUtilTest {
|
||||
Assert.assertEquals(1001013, NumberUtil.div(100101300, (Number) 100).intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDoubleTest(){
|
||||
Assert.assertFalse(NumberUtil.isDouble(null));
|
||||
Assert.assertFalse(NumberUtil.isDouble(""));
|
||||
Assert.assertFalse(NumberUtil.isDouble(" "));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user