mirror of
https://gitee.com/dromara/hutool.git
synced 2025-09-18 17:48:17 +08:00
修复NumberWordFormatter
formatSimple输出错误问题(pr#4034@Github)
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
# 🚀Changelog
|
# 🚀Changelog
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.40(2025-08-25)
|
# 5.8.40(2025-08-26)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【captcha】 `MathGenerator`四则运算方式支持不生成负数结果(pr#1363@Gitee)
|
* 【captcha】 `MathGenerator`四则运算方式支持不生成负数结果(pr#1363@Gitee)
|
||||||
@@ -22,7 +22,8 @@
|
|||||||
* 【extra 】 修复`QLExpressEngine`allowClassSet无效问题(issue#3994@Github)
|
* 【extra 】 修复`QLExpressEngine`allowClassSet无效问题(issue#3994@Github)
|
||||||
* 【core 】 修复`StrBuilder`insert插入计算错误问题(issue#ICTSRZ@Gitee)
|
* 【core 】 修复`StrBuilder`insert插入计算错误问题(issue#ICTSRZ@Gitee)
|
||||||
* 【cron 】 修复`CronPatternUtil.nextDateAfter`计算下一个匹配表达式的日期时,计算错误问题(issue#4006@Github)
|
* 【cron 】 修复`CronPatternUtil.nextDateAfter`计算下一个匹配表达式的日期时,计算错误问题(issue#4006@Github)
|
||||||
* 【cache 】 `ReentrantCache`修改get逻辑key锁改为全局锁,保证安全。(issue#4022@Github)
|
* 【cache 】 `ReentrantCache`修改get逻辑key锁改为全局锁,保证安全(issue#4022@Github)
|
||||||
|
* 【core 】 修复`NumberWordFormatter`formatSimple输出错误问题(pr#4034@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.39(2025-06-20)
|
# 5.8.39(2025-06-20)
|
||||||
|
@@ -66,11 +66,11 @@ public class NumberWordFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double res = value;
|
double res = value;
|
||||||
int index = 0;
|
final int index;
|
||||||
|
|
||||||
if (isTwo) {
|
if (isTwo) {
|
||||||
// 当isTwo为true时,只使用k和w单位
|
// 当isTwo为true时,只使用k和w单位
|
||||||
if (value >= 100000) {
|
if (value >= 10000) {
|
||||||
// 使用w单位(除以10000,即10k = 1w)
|
// 使用w单位(除以10000,即10k = 1w)
|
||||||
res = value / 10000.0;
|
res = value / 10000.0;
|
||||||
index = 1; // w在NUMBER_SUFFIX[1]
|
index = 1; // w在NUMBER_SUFFIX[1]
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
package cn.hutool.core.convert;
|
package cn.hutool.core.convert;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class NumberWordFormatTest {
|
public class NumberWordFormatTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -43,4 +45,52 @@ public class NumberWordFormatTest {
|
|||||||
final String s = NumberWordFormatter.formatSimple(1000);
|
final String s = NumberWordFormatter.formatSimple(1000);
|
||||||
assertEquals("1k", s);
|
assertEquals("1k", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void issue4033Test(){
|
||||||
|
String s = NumberWordFormatter.formatSimple(1_000, false);
|
||||||
|
Assertions.assertEquals("1k", s);
|
||||||
|
|
||||||
|
s = NumberWordFormatter.formatSimple(10_000, false);
|
||||||
|
Assertions.assertEquals("10k", s);
|
||||||
|
|
||||||
|
s = NumberWordFormatter.formatSimple(100_000, false);
|
||||||
|
Assertions.assertEquals("100k", s);
|
||||||
|
|
||||||
|
s = NumberWordFormatter.formatSimple(1_000_000, false);
|
||||||
|
Assertions.assertEquals("1m", s);
|
||||||
|
|
||||||
|
s = NumberWordFormatter.formatSimple(10_000_000, false);
|
||||||
|
Assertions.assertEquals("10m", s);
|
||||||
|
|
||||||
|
s = NumberWordFormatter.formatSimple(100_000_000, false);
|
||||||
|
Assertions.assertEquals("100m", s);
|
||||||
|
|
||||||
|
s = NumberWordFormatter.formatSimple(1_000_000_000, false);
|
||||||
|
Assertions.assertEquals("1b", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void issue4033Test2(){
|
||||||
|
String s = NumberWordFormatter.formatSimple(1_000, true);
|
||||||
|
Assertions.assertEquals("1k", s);
|
||||||
|
|
||||||
|
s = NumberWordFormatter.formatSimple(10_000, true);
|
||||||
|
Assertions.assertEquals("1w", s);
|
||||||
|
|
||||||
|
s = NumberWordFormatter.formatSimple(100_000, true);
|
||||||
|
Assertions.assertEquals("10w", s);
|
||||||
|
|
||||||
|
s = NumberWordFormatter.formatSimple(1_000_000, true);
|
||||||
|
Assertions.assertEquals("100w", s);
|
||||||
|
|
||||||
|
s = NumberWordFormatter.formatSimple(10_000_000, true);
|
||||||
|
Assertions.assertEquals("1000w", s);
|
||||||
|
|
||||||
|
s = NumberWordFormatter.formatSimple(100_000_000, true);
|
||||||
|
Assertions.assertEquals("10000w", s);
|
||||||
|
|
||||||
|
s = NumberWordFormatter.formatSimple(1_000_000_000, true);
|
||||||
|
Assertions.assertEquals("100000w", s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user