From f77311c6c784370497012fa2ef7063303c9bcedc Mon Sep 17 00:00:00 2001 From: lihao Date: Fri, 6 Jun 2025 14:59:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=98=E6=AC=BE=E5=8D=95=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=87=AA=E5=AE=9A=E4=B9=89=E9=A1=B9=E8=B5=8B?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../private/nc/bs/pub/action/N_F3_SAVE.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/arap/src/private/nc/bs/pub/action/N_F3_SAVE.java b/arap/src/private/nc/bs/pub/action/N_F3_SAVE.java index 4baca74..6c9728b 100644 --- a/arap/src/private/nc/bs/pub/action/N_F3_SAVE.java +++ b/arap/src/private/nc/bs/pub/action/N_F3_SAVE.java @@ -145,23 +145,26 @@ public class N_F3_SAVE extends N_BASE_ACTION { } else { char[] intChars = integerPart.toCharArray(); int len = intChars.length; - int index = 0; - for (int i = len - 1; i >= 0; i--) { + for (int i = 0; i < len; i++) { int digit = intChars[i] - '0'; int digitPosition = len - i - 1; int section = digitPosition / 4; int positionInSection = digitPosition % 4; if (digit != 0) { - chineseInteger.insert(0, CHINESE_CHARS[digit]); + chineseInteger.append(CHINESE_CHARS[digit]); if (positionInSection > 0) { - chineseInteger.insert(0, DIGIT_UNITS[positionInSection]); + chineseInteger.append(DIGIT_UNITS[positionInSection]); } } - if (positionInSection == 0 && digit != 0) { - chineseInteger.insert(0, LARGE_NUMBERS[section]); + if (positionInSection == 0) { + if (digit != 0 || chineseInteger.length() == 0) { + chineseInteger.append(LARGE_NUMBERS[section]); + } + } + if (digit == 0) { + chineseInteger.append(CHINESE_CHARS[digit]); } - index++; } // 移除多余的零和重复的单位 cleanUpChineseNumber(chineseInteger); @@ -169,9 +172,9 @@ public class N_F3_SAVE extends N_BASE_ACTION { // 处理小数部分 StringBuilder chineseDecimal = new StringBuilder(); + int jiao = 0; + int fen = 0; if (!decimalPart.isEmpty()) { - int jiao = 0; - int fen = 0; if (decimalPart.length() >= 1) { jiao = Integer.parseInt(decimalPart.substring(0, 1)); } @@ -181,6 +184,7 @@ public class N_F3_SAVE extends N_BASE_ACTION { if (jiao != 0) { chineseDecimal.append(CHINESE_CHARS[jiao]).append(AMOUNT_UNITS[1]); } + // 如果分不为0,才输出分部分 if (fen != 0) { chineseDecimal.append(CHINESE_CHARS[fen]).append(AMOUNT_UNITS[2]); } @@ -191,10 +195,14 @@ public class N_F3_SAVE extends N_BASE_ACTION { chineseInteger.append(CHINESE_CHARS[0]); } chineseInteger.append(AMOUNT_UNITS[0]); - if (chineseDecimal.length() == 0) { + if (jiao == 0 && fen == 0) { chineseInteger.append("整"); } else { - chineseInteger.append(chineseDecimal); + if (fen == 0 && jiao != 0) { + chineseInteger.append(chineseDecimal).append("整"); + } else { + chineseInteger.append(chineseDecimal); + } } // 特殊情况处理:零元整 @@ -214,7 +222,7 @@ public class N_F3_SAVE extends N_BASE_ACTION { if (sb.length() > 0 && sb.charAt(sb.length() - 1) == '零') { sb.deleteCharAt(sb.length() - 1); } - // 除单位前面的零 + // 移除单位前面的零 for (String unit : DIGIT_UNITS) { if (!unit.isEmpty()) { while (sb.indexOf("零" + unit) != -1) { @@ -232,4 +240,5 @@ public class N_F3_SAVE extends N_BASE_ACTION { } } + }