From 858be6aafa125d912da0253daf632ba59b6ae8b2 Mon Sep 17 00:00:00 2001 From: Looly Date: Wed, 18 May 2022 10:35:31 +0800 Subject: [PATCH] fix bug --- .../java/cn/hutool/core/convert/NumberWordFormatter.java | 2 +- .../java/cn/hutool/core/convert/NumberWordFormatTest.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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 12c3853c6..98a42240c 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 64acfad96..7b39d1a9f 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 { final String format5 = NumberWordFormatter.formatSimple(438); Assert.assertEquals("438", format5); } + + @Test + public void formatSimpleTest2(){ + final String s = NumberWordFormatter.formatSimple(1000); + Assert.assertEquals("1k", s); + } }