17 lines
539 B
TypeScript
17 lines
539 B
TypeScript
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;
|
||
}
|