a7a0a54688
Co-authored-by: Cursor <cursoragent@cursor.com>
10 lines
426 B
TypeScript
10 lines
426 B
TypeScript
/** 金额展示(不依赖 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}`;
|
|
}
|