mirror of
https://github.com/Such-Software/xmrcheckout.git
synced 2026-10-17 05:51:34 +02:00
25 lines
659 B
TypeScript
25 lines
659 B
TypeScript
export const formatXmrAmount = (value: string | number): string => {
|
|
const raw = typeof value === "number" ? value.toString() : value;
|
|
if (!raw) {
|
|
return "";
|
|
}
|
|
const [whole, fraction] = raw.split(".");
|
|
if (!fraction) {
|
|
return raw;
|
|
}
|
|
const trimmedFraction = fraction.replace(/0+$/, "");
|
|
return trimmedFraction ? `${whole}.${trimmedFraction}` : whole;
|
|
};
|
|
|
|
export const formatUsdAmount = (value: number): string => {
|
|
if (!Number.isFinite(value)) {
|
|
return "";
|
|
}
|
|
return new Intl.NumberFormat("en-US", {
|
|
style: "currency",
|
|
currency: "USD",
|
|
maximumFractionDigits: 2,
|
|
minimumFractionDigits: 2,
|
|
}).format(value);
|
|
};
|