From 3f8699f7e940ba1689054966e0a7c09de9d079a7 Mon Sep 17 00:00:00 2001 From: Looly Date: Wed, 18 May 2022 10:33:21 +0800 Subject: [PATCH] fix bug --- CHANGELOG.md | 1 + .../java/cn/hutool/core/convert/NumberWordFormatter.java | 2 +- .../java/cn/hutool/core/convert/NumberWordFormatTest.java | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 230c2ddc5..8122799e0 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### 🐣新特性 ### 🐞Bug修复 * 【extra 】 修复SshjSftp初始化未能代入端口配置问题(issue#2333@Github) +* 【core 】 修复Convert.numberToSimple转换问题(issue#2334@Github) ------------------------------------------------------------------------------------------------------------- diff --git a/hutool-core/src/main/java/cn/hutool/core/convert/NumberWordFormatter.java b/hutool-core/src/main/java/cn/hutool/core/convert/NumberWordFormatter.java index 22c0d057b..e835593e4 100644 --- a/hutool-core/src/main/java/cn/hutool/core/convert/NumberWordFormatter.java +++ b/hutool-core/src/main/java/cn/hutool/core/convert/NumberWordFormatter.java @@ -63,7 +63,7 @@ public class NumberWordFormatter { int index = -1; double res = value; while (res > 10 && (false == isTwo || index < 1)) { - if (res > 1000) { + if (res >= 1000) { res = res / 1000; index++; } diff --git a/hutool-core/src/test/java/cn/hutool/core/convert/NumberWordFormatTest.java b/hutool-core/src/test/java/cn/hutool/core/convert/NumberWordFormatTest.java index 629205404..802d621c4 100644 --- a/hutool-core/src/test/java/cn/hutool/core/convert/NumberWordFormatTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/convert/NumberWordFormatTest.java @@ -31,4 +31,10 @@ public class NumberWordFormatTest { String format5 = NumberWordFormatter.formatSimple(438); Assert.assertEquals("438", format5); } + + @Test + public void formatSimpleTest2(){ + final String s = NumberWordFormatter.formatSimple(1000); + Assert.assertEquals("1k", s); + } }