From 53204e5e5bfe8c15f07bab7f8d2b05e0983bb33b Mon Sep 17 00:00:00 2001 From: Looly Date: Thu, 15 Sep 2022 23:17:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DConvert.chineseMoneyToNumber?= =?UTF-8?q?=E8=A7=92=E5=88=86=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../hutool/core/convert/NumberChineseFormatter.java | 6 ++---- .../java/cn/hutool/core/convert/ConvertTest.java | 12 ++++++------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11b94bc5e..c53ed0299 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ * 【extra 】 修复Ftp中路径问题(issue#I5R2DE@Gitee) * 【core 】 修复ConcurrentHashMap.computeIfAbsent缺陷导致的问题 * 【core 】 修复DateUtil.parseUTC时对-的处理问题(issue#2612@Github) +* 【core 】 修复Convert.chineseMoneyToNumber角分丢失问题(issue#2611@Github) ------------------------------------------------------------------------------------------------------------- diff --git a/hutool-core/src/main/java/cn/hutool/core/convert/NumberChineseFormatter.java b/hutool-core/src/main/java/cn/hutool/core/convert/NumberChineseFormatter.java index ebf0be822..71fd6fa1d 100644 --- a/hutool-core/src/main/java/cn/hutool/core/convert/NumberChineseFormatter.java +++ b/hutool-core/src/main/java/cn/hutool/core/convert/NumberChineseFormatter.java @@ -237,7 +237,6 @@ public class NumberChineseFormatter { /** * 中文大写数字金额转换为数字,返回结果以元为单位的BigDecimal类型数字 - * * 如: * “陆万柒仟伍佰伍拾陆元叁角贰分”返回“67556.32” * “叁角贰分”返回“0.32” @@ -310,8 +309,8 @@ public class NumberChineseFormatter { } BigDecimal amount = new BigDecimal(y); - amount = amount.add(BigDecimal.valueOf(j).divide(BigDecimal.TEN, RoundingMode.HALF_UP)); - amount = amount.add(BigDecimal.valueOf(f).divide(BigDecimal.valueOf(100), RoundingMode.HALF_UP)); + amount = amount.add(BigDecimal.valueOf(j).divide(BigDecimal.TEN, 2, RoundingMode.HALF_UP)); + amount = amount.add(BigDecimal.valueOf(f).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP)); return amount; } @@ -440,7 +439,6 @@ public class NumberChineseFormatter { /** * 把中文转换为数字 如 二百二十 220
- * 见:https://www.d5.nz/read/sfdlq/text-part0000_split_030.html *