mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
修复Convert.digitToChinese(0)输出金额无元整问题
This commit is contained in:
@@ -1030,7 +1030,7 @@ public class Convert {
|
||||
*/
|
||||
public static String digitToChinese(Number n) {
|
||||
if (null == n) {
|
||||
return "零";
|
||||
n = 0;
|
||||
}
|
||||
return NumberChineseFormatter.format(n.doubleValue(), true, true);
|
||||
}
|
||||
|
@@ -92,7 +92,7 @@ public class NumberChineseFormatter {
|
||||
*/
|
||||
public static String format(double amount, boolean isUseTraditional, boolean isMoneyMode, String negativeName, String unitName) {
|
||||
if (0 == amount) {
|
||||
return "零";
|
||||
return isMoneyMode ? "零元整" : "零";
|
||||
}
|
||||
Assert.checkBetween(amount, -99_9999_9999_9999.99, 99_9999_9999_9999.99,
|
||||
"Number support only: (-99999999999999.99 ~ 99999999999999.99)!");
|
||||
|
@@ -435,4 +435,12 @@ public class ConvertTest {
|
||||
Assert.assertEquals(12, s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void issue3662Test() {
|
||||
String s = Convert.digitToChinese(0);
|
||||
Assert.assertEquals("零元整", s);
|
||||
|
||||
s = Convert.digitToChinese(null);
|
||||
Assert.assertEquals("零元整", s);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user