mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix bug
This commit is contained in:
@@ -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(" "));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user