mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-12-06 17:18:54 +08:00
Compare commits
3 Commits
8003c4416a
...
ff32ed0872
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff32ed0872 | ||
|
|
9f6d3b5430 | ||
|
|
f9eb29fa87 |
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
# 🚀Changelog
|
# 🚀Changelog
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.42(2025-11-17)
|
# 5.8.42(2025-11-20)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【core 】 `ListUtil`增加`zip`方法(pr#4052@Github)
|
* 【core 】 `ListUtil`增加`zip`方法(pr#4052@Github)
|
||||||
@ -20,6 +20,7 @@
|
|||||||
* 【core 】 修复`NumberWithFormat`没有实现Comparable接口导致的JSON排序报错问题(issue#ID61QR@Gitee)
|
* 【core 】 修复`NumberWithFormat`没有实现Comparable接口导致的JSON排序报错问题(issue#ID61QR@Gitee)
|
||||||
* 【core 】 修复`ImgUtil.write`没有释放BufferedImage可能导致内存泄露(issue#ID6VNJ@Gitee)
|
* 【core 】 修复`ImgUtil.write`没有释放BufferedImage可能导致内存泄露(issue#ID6VNJ@Gitee)
|
||||||
* 【core 】 修复`VersionUtil.matchEl`如果输入的版本范围表达式右边界为空时,会抛出数组越界访问错误的问题(pr#4130@Github)
|
* 【core 】 修复`VersionUtil.matchEl`如果输入的版本范围表达式右边界为空时,会抛出数组越界访问错误的问题(pr#4130@Github)
|
||||||
|
* 【core 】 修复`Validator.isBetween`在高精度Number类型下存在精度丢失问题(pr#4136@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.41(2025-10-12)
|
# 5.8.41(2025-10-12)
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import cn.hutool.core.util.ReUtil;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.core.util.IdcardUtil;
|
import cn.hutool.core.util.IdcardUtil;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -1123,8 +1124,11 @@ public class Validator {
|
|||||||
Assert.notNull(value);
|
Assert.notNull(value);
|
||||||
Assert.notNull(min);
|
Assert.notNull(min);
|
||||||
Assert.notNull(max);
|
Assert.notNull(max);
|
||||||
final double doubleValue = value.doubleValue();
|
// 通过 NumberUtil 转换为 BigDecimal,使用 BigDecimal 进行比较以保留精度
|
||||||
return (doubleValue >= min.doubleValue()) && (doubleValue <= max.doubleValue());
|
BigDecimal valBd = NumberUtil.toBigDecimal(value);
|
||||||
|
BigDecimal minBd = NumberUtil.toBigDecimal(min);
|
||||||
|
BigDecimal maxBd = NumberUtil.toBigDecimal(max);
|
||||||
|
return valBd.compareTo(minBd) >= 0 && valBd.compareTo(maxBd) <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -227,6 +227,19 @@ public class ValidatorTest {
|
|||||||
assertTrue(Validator.isBetween(0.19, 0.1, 0.2));
|
assertTrue(Validator.isBetween(0.19, 0.1, 0.2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isBetweenPrecisionLossTest() {
|
||||||
|
// 使用超过 double 精度的值
|
||||||
|
long base = 10000000000000000L;
|
||||||
|
long min = base + 1;
|
||||||
|
long max = base + 2;
|
||||||
|
|
||||||
|
// 在 double 转换下,base、min 和 max 是完全相等的,因为 double 精度不够
|
||||||
|
// 预期结果为false,但是因为double 精度不够,导致输出为true
|
||||||
|
assertFalse(Validator.isBetween(base, min, max));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isCarVinTest() {
|
public void isCarVinTest() {
|
||||||
assertTrue(Validator.isCarVin("LSJA24U62JG269225"));
|
assertTrue(Validator.isCarVin("LSJA24U62JG269225"));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user