This commit is contained in:
2025-10-01 16:25:39 +08:00
parent 8440329fbc
commit 4a2358629b
9 changed files with 60 additions and 423 deletions
+17 -7
View File
@@ -96,11 +96,21 @@ def gold_to_string(gold_amount):
Returns:
str: 格式化后的金钱字符串,例如 "1金2银3铜"
"""
bricks = gold_amount // 100000000 if gold_amount else 0
gold = (gold_amount % 100000000) // 10000 if gold_amount else 0
silver = (gold_amount % 10000) // 100 if gold_amount else 0
copper = gold_amount % 100 if gold_amount else 0
gold_str = f"{bricks}{gold}{silver}{copper}" if gold_amount else "无价格"
if not gold_amount:
return "无价格"
return gold_str
parts = []
started = False # 标记是否已经遇到第一个非零位
bricks = gold_amount // 100000000
gold = (gold_amount % 100000000) // 10000
silver = (gold_amount % 10000) // 100
copper = gold_amount % 100
for value, unit in [(bricks, ""), (gold, ""), (silver, ""), (copper, "")]:
if value != 0:
started = True
if started:
parts.append(f"{value}{unit}")
return "".join(parts)