mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-05 21:28:00 +08:00
NumberChineseFormatter提供阿拉伯转中文支持多位小数的方法
This commit is contained in:
parent
8279681651
commit
c02460423e
@ -2,7 +2,7 @@
|
|||||||
# 🚀Changelog
|
# 🚀Changelog
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.28(2024-04-20)
|
# 5.8.28(2024-04-21)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【core 】 修正XmlUtil的omitXmlDeclaration描述注释(issue#I9CPC7@Gitee)
|
* 【core 】 修正XmlUtil的omitXmlDeclaration描述注释(issue#I9CPC7@Gitee)
|
||||||
@ -11,6 +11,7 @@
|
|||||||
* 【extra 】 增加设置验证码大小和针对alias注释(pr#3533@Github)
|
* 【extra 】 增加设置验证码大小和针对alias注释(pr#3533@Github)
|
||||||
* 【json 】 JSONConfig增加setWriteLongAsString可选是否将Long写出为String类型(issue#3541@Github)
|
* 【json 】 JSONConfig增加setWriteLongAsString可选是否将Long写出为String类型(issue#3541@Github)
|
||||||
* 【cache 】 CacheUtil.newTimedCache增加有schedulePruneDelay参数的重载方法(issue#I9HO25@Gitee)
|
* 【cache 】 CacheUtil.newTimedCache增加有schedulePruneDelay参数的重载方法(issue#I9HO25@Gitee)
|
||||||
|
* 【core 】 NumberChineseFormatter提供阿拉伯转中文支持多位小数的方法(pr#3552@Github)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【http 】 修复HttpUtil.urlWithFormUrlEncoded方法重复编码问题(issue#3536@Github)
|
* 【http 】 修复HttpUtil.urlWithFormUrlEncoded方法重复编码问题(issue#3536@Github)
|
||||||
|
@ -51,6 +51,7 @@ public class NumberChineseFormatter {
|
|||||||
* 口语化映射
|
* 口语化映射
|
||||||
*/
|
*/
|
||||||
private static final Map<String, String> COLLOQUIAL_WORDS = new HashMap<String, String>() {
|
private static final Map<String, String> COLLOQUIAL_WORDS = new HashMap<String, String>() {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
{
|
{
|
||||||
put("一十", "十");
|
put("一十", "十");
|
||||||
put("一拾", "拾");
|
put("一拾", "拾");
|
||||||
@ -244,6 +245,7 @@ public class NumberChineseFormatter {
|
|||||||
* @param isUseTraditional 是否使用繁体
|
* @param isUseTraditional 是否使用繁体
|
||||||
* @param isUseColloquial 是否使用口语化(e.g. 一十 -> 十)
|
* @param isUseColloquial 是否使用口语化(e.g. 一十 -> 十)
|
||||||
* @return 中文
|
* @return 中文
|
||||||
|
* @since 5.8.28
|
||||||
*/
|
*/
|
||||||
public static String format(BigDecimal amount, boolean isUseTraditional, boolean isUseColloquial) {
|
public static String format(BigDecimal amount, boolean isUseTraditional, boolean isUseColloquial) {
|
||||||
String formatAmount;
|
String formatAmount;
|
||||||
|
@ -3,6 +3,8 @@ package cn.hutool.core.convert;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
public class NumberChineseFormatterTest {
|
public class NumberChineseFormatterTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -342,4 +344,10 @@ public class NumberChineseFormatterTest {
|
|||||||
format = NumberChineseFormatter.format(1.02, false, false);
|
format = NumberChineseFormatter.format(1.02, false, false);
|
||||||
Assert.assertEquals("一点零二", format);
|
Assert.assertEquals("一点零二", format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void dotTest() {
|
||||||
|
final String format = NumberChineseFormatter.format(new BigDecimal("3.1415926"), false, false);
|
||||||
|
Assert.assertEquals("三点一四一五九二六", format);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user