Skip to content

Commit

Permalink
fix: number formatting on main value element
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Oct 26, 2024
1 parent 9229ec1 commit 2786009
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/pages/wallet/New.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -158,7 +162,7 @@ export function New() {
<div className="flex flex-col items-center justify-center w-full flex-1 mb-4">
<div className="flex flex-1 flex-col mb-4 items-center justify-center">
<p className="text-7xl pb-2 whitespace-nowrap text-center mx-auto">
{formatNumber(amount)}
{formatNumber(amount, true)}
</p>
<div className="flex items-center justify-center">
<select
Expand Down

0 comments on commit 2786009

Please sign in to comment.