NumberChineseFormatter提供阿拉伯转中文支持多位小数的方法

This commit is contained in:
Looly
2024-04-21 08:12:07 +08:00
parent 8279681651
commit c02460423e
3 changed files with 12 additions and 1 deletions

View File

@@ -51,6 +51,7 @@ public class NumberChineseFormatter {
* 口语化映射
*/
private static final Map<String, String> COLLOQUIAL_WORDS = new HashMap<String, String>() {
private static final long serialVersionUID = 1L;
{
put("一十", "");
put("一拾", "");
@@ -244,6 +245,7 @@ public class NumberChineseFormatter {
* @param isUseTraditional 是否使用繁体
* @param isUseColloquial 是否使用口语化(e.g. 一十 -> 十)
* @return 中文
* @since 5.8.28
*/
public static String format(BigDecimal amount, boolean isUseTraditional, boolean isUseColloquial) {
String formatAmount;

View File

@@ -3,6 +3,8 @@ package cn.hutool.core.convert;
import org.junit.Assert;
import org.junit.Test;
import java.math.BigDecimal;
public class NumberChineseFormatterTest {
@Test
@@ -342,4 +344,10 @@ public class NumberChineseFormatterTest {
format = NumberChineseFormatter.format(1.02, false, false);
Assert.assertEquals("一点零二", format);
}
@Test
public void dotTest() {
final String format = NumberChineseFormatter.format(new BigDecimal("3.1415926"), false, false);
Assert.assertEquals("三点一四一五九二六", format);
}
}