|
|
@@ -27,6 +27,15 @@ def _normalize_amount_token(token: str) -> str:
|
|
|
if core[0] in "+-":
|
|
|
sign, core = core[0], core[1:]
|
|
|
|
|
|
+ # 条件1:去符号后为纯整数(无分隔符),无需处理
|
|
|
+ if core.isdigit():
|
|
|
+ return token
|
|
|
+
|
|
|
+ # 条件2:最后一个小数点之前无逗号/小数点(整数部分是纯数字)→ 已是正确小数格式,直接返回
|
|
|
+ dot_pos = core.rfind('.')
|
|
|
+ if dot_pos != -1 and core[:dot_pos].isdigit() and core[dot_pos + 1:].isdigit():
|
|
|
+ return token
|
|
|
+
|
|
|
# 步骤 1:确定小数分隔符('.' 优先于 ',')
|
|
|
dec_digits: str | None = None
|
|
|
int_part = core
|
|
|
@@ -45,6 +54,14 @@ def _normalize_amount_token(token: str) -> str:
|
|
|
if not int_digits or not int_digits.isdigit():
|
|
|
return token # 无法解析,保留原样
|
|
|
|
|
|
+ # 步骤 2.5:整数部分本身没有分隔符(如 1101,55 中的 1101)
|
|
|
+ # → 原数字未使用千分位,只修正小数点符号,不添加千分位
|
|
|
+ if int_part == int_digits:
|
|
|
+ result = sign + int_digits
|
|
|
+ if dec_digits is not None:
|
|
|
+ result += "." + dec_digits
|
|
|
+ return result
|
|
|
+
|
|
|
# 步骤 3:重新做千分位分组
|
|
|
n = len(int_digits)
|
|
|
rem = n % 3 or 3
|