fix(web-admin): avoid duplicate 零 in RMB uppercase for yi+rest

Add regression tests for 亿到元段间零填充。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-07-30 11:01:33 +08:00
1 parent e6d7eecdc6
commit 0a24f707bf
2 files changed
+11 -4

No files matched your search

+5
View File
@@ -35,4 +35,9 @@ describe('toRmbUpper', () => {
assert.ok(s.includes('角') || s.includes('分'))
assert.notEqual(s, '金额过大')
})
it('yi to yuan zero padding', () => {
assert.equal(toRmbUpper(100000001), '壹亿零壹元整')
assert.equal(toRmbUpper(100000010), '壹亿零壹拾元整')
assert.equal(toRmbUpper(100010000), '壹亿零壹万元整')
})
})
+6 -4
View File
@@ -44,7 +44,7 @@ export function toRmbUpper(value: number | null | undefined): string {
if (yuan > 0) {
const yi = Math.floor(yuan / 100000000)
const wan = Math.floor((yuan % 100000000) / 10000)
const wan = Math.floor(yuan / 10000) % 10000
const rest = yuan % 10000
if (yi > 0) {
@@ -55,11 +55,13 @@ export function toRmbUpper(value: number | null | undefined): string {
result += '零'
}
result += sectionToChinese(wan) + '万'
} else if (yi > 0 && rest > 0) {
result += '零'
}
if (rest > 0) {
if ((yi > 0 || wan > 0) && rest < 1000) {
if (wan > 0) {
if (rest < 1000) {
result += '零'
}
} else if (yi > 0) {
result += '零'
}
result += sectionToChinese(rest)