v3.5.3版本更新1
CI / verify (pull_request) Has been cancelled

This commit is contained in:
2026-08-20 18:54:15 +08:00
parent ee493823bf
commit fc2e5b65de
65 changed files with 2297 additions and 875 deletions
+21 -2
View File
@@ -1,7 +1,26 @@
/** 金额展示(不依赖 Intl / toLocaleString,兼容微信小程序) */
export function toMoneyNumber(amount: unknown): number {
if (typeof amount === 'number') return Number.isFinite(amount) ? amount : 0;
if (typeof amount === 'string' && amount.trim()) {
const n = Number(amount);
return Number.isFinite(n) ? n : 0;
}
if (amount && typeof amount === 'object') {
const o = amount as { toNumber?: () => number; toString?: () => string };
if (typeof o.toNumber === 'function') {
const n = Number(o.toNumber());
if (Number.isFinite(n)) return n;
}
if (typeof o.toString === 'function' && o.toString !== Object.prototype.toString) {
const n = Number(o.toString());
if (Number.isFinite(n)) return n;
}
}
return 0;
}
export function formatMoney(amount: number | string): string {
const n = typeof amount === 'number' ? amount : Number(amount);
if (!Number.isFinite(n)) return '0.00';
const n = toMoneyNumber(amount);
const fixed = n.toFixed(2);
const [intPart, dec] = fixed.split('.');
const withComma = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');