mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix bug
This commit is contained in:
@@ -1242,12 +1242,13 @@ public class NumberUtil {
|
||||
* @return 是否为整数
|
||||
*/
|
||||
public static boolean isInteger(final String s) {
|
||||
if(StrUtil.isNotBlank(s)) {
|
||||
try {
|
||||
Integer.parseInt(s);
|
||||
} catch (final NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
if(StrUtil.isBlank(s)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Integer.parseInt(s);
|
||||
} catch (final NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1261,12 +1262,13 @@ public class NumberUtil {
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public static boolean isLong(final String s) {
|
||||
if (StrUtil.isNotBlank(s)) {
|
||||
try {
|
||||
Long.parseLong(s);
|
||||
} catch (final NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
if(StrUtil.isBlank(s)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Long.parseLong(s);
|
||||
} catch (final NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1278,15 +1280,16 @@ public class NumberUtil {
|
||||
* @return 是否为{@link Double}类型
|
||||
*/
|
||||
public static boolean isDouble(final String s) {
|
||||
if (StrUtil.isNotBlank(s)) {
|
||||
try {
|
||||
Double.parseDouble(s);
|
||||
return s.contains(".");
|
||||
} catch (final NumberFormatException ignore) {
|
||||
// ignore
|
||||
}
|
||||
if(StrUtil.isBlank(s)) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
try {
|
||||
Double.parseDouble(s);
|
||||
return s.contains(".");
|
||||
} catch (final NumberFormatException ignore) {
|
||||
// ignore
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -62,6 +62,9 @@ public class NumberUtilTest {
|
||||
Assert.assertTrue(NumberUtil.isInteger("0256"));
|
||||
Assert.assertTrue(NumberUtil.isInteger("0"));
|
||||
Assert.assertFalse(NumberUtil.isInteger("23.4"));
|
||||
Assert.assertFalse(NumberUtil.isInteger(null));
|
||||
Assert.assertFalse(NumberUtil.isInteger(""));
|
||||
Assert.assertFalse(NumberUtil.isInteger(" "));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,6 +74,9 @@ public class NumberUtilTest {
|
||||
Assert.assertTrue(NumberUtil.isLong("0256"));
|
||||
Assert.assertTrue(NumberUtil.isLong("0"));
|
||||
Assert.assertFalse(NumberUtil.isLong("23.4"));
|
||||
Assert.assertFalse(NumberUtil.isLong(null));
|
||||
Assert.assertFalse(NumberUtil.isLong(""));
|
||||
Assert.assertFalse(NumberUtil.isLong(" "));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user