ldc-cocotte/resources/ts/modules/currency-formatter.ts
2026-10-27 09:58:12 +01:00

17 lines
539 B
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export default function number_format(amount: number|null, to_float: boolean = false): string | number {
if (Number.isNaN(amount) || amount === null) {
return "-.--";
}
const locale = "fr";
const formatted_string = new Intl.NumberFormat(locale, {
style: "currency",
currency: "eur",
minimumFractionDigits: 2,
maximumFractionDigits: 2
}).format(amount);
if (to_float) {
return Number.parseFloat(formatted_string.replace(",", ".").replace("€", "").replace(" ", ""));
}
return formatted_string;
}