From 75131c8d6c07aae29a71bd92fea2489b02ec18a1 Mon Sep 17 00:00:00 2001 From: admin <1297598740@qq.com> Date: Wed, 28 Jan 2026 16:49:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20`money.ts`=20?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E6=96=87=E4=BB=B6=EF=BC=8C=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E5=9F=BA=E4=BA=8E=20`decimal.js`=20=E7=9A=84=E7=B2=BE=E7=A1=AE?= =?UTF-8?q?=E9=87=91=E9=A2=9D=E8=AE=A1=E7=AE=97=E5=92=8C=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/money.ts | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/utils/money.ts b/src/utils/money.ts index f837839..892e33a 100644 --- a/src/utils/money.ts +++ b/src/utils/money.ts @@ -75,16 +75,26 @@ export const Money = { }, /** - * Format money for display with currency symbol + * Format money for display with currency symbol (Standard v7.0) */ format(value: number | string, currency: string = 'CNY'): string { - const num = new Decimal(value).toDecimalPlaces(2).toNumber(); - const symbol = CURRENCY_SYMBOLS[currency] || currency; - const formatted = num.toLocaleString('zh-CN', { - minimumFractionDigits: 2, - maximumFractionDigits: 2, - }); - return `${symbol}${formatted}`; + const num = new Decimal(value).toNumber(); + try { + return new Intl.NumberFormat('zh-CN', { + style: 'currency', + currency: currency, + minimumFractionDigits: 2, + maximumFractionDigits: 2, + }).format(num); + } catch (e) { + // Fallback for invalid currency codes + const symbol = CURRENCY_SYMBOLS[currency] || currency; + const formatted = num.toLocaleString('zh-CN', { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + }); + return `${symbol}${formatted}`; + } }, /**