From 278600903555e06b247a6b37c62bfdba1d1d3a35 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Sat, 26 Oct 2024 23:42:27 +0700 Subject: [PATCH] fix: number formatting on main value element --- src/pages/wallet/New.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pages/wallet/New.tsx b/src/pages/wallet/New.tsx index fd9e67a..576bfe9 100644 --- a/src/pages/wallet/New.tsx +++ b/src/pages/wallet/New.tsx @@ -126,13 +126,17 @@ export function New() { setAmount(0); }; - const formatNumber = (num: number) => { + const formatNumber = (num: number, numberOnly = false) => { if (currency === "SATS") { return num.toString(); } - return new Intl.NumberFormat("en-US", { style: "currency", currency: currency }).format( + let result = new Intl.NumberFormat("en-US", { style: "currency", currency: currency }).format( num / 100 ); + if (numberOnly) { + result = result.replace(/[^0-9\\.,]/g, ""); // e.g. remove "THB " prefix as it takes too much space + } + return result; }; const handleSetLabel = () => { @@ -158,7 +162,7 @@ export function New() {

- {formatNumber(amount)} + {formatNumber(amount, true)}