fix(mini-user): 微信小程序补 Intl 兜底并去掉 toLocaleString

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-03 14:53:54 +08:00
parent 04fd4d50d0
commit a7a0a54688
9 changed files with 93 additions and 26 deletions
+9
View File
@@ -0,0 +1,9 @@
/** 金额展示(不依赖 Intl / toLocaleString,兼容微信小程序) */
export function formatMoney(amount: number | string): string {
const n = typeof amount === 'number' ? amount : Number(amount);
if (!Number.isFinite(n)) return '0.00';
const fixed = n.toFixed(2);
const [intPart, dec] = fixed.split('.');
const withComma = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return `${withComma}.${dec}`;
}