Intl formats numbers and dates, so do not hand-roll it
Every hand-written thousands separator or relative time string is wrong for some locale. The platform has formatters for all of it.
new Intl.NumberFormat("en-GB", { style: "currency", currency: "GBP" }).format(1234.5);
new Intl.RelativeTimeFormat("en", { numeric: "auto" }).format(-1, "day"); // "yesterday"
new Intl.DateTimeFormat("de-DE", { dateStyle: "medium" }).format(date);Create the formatter once and reuse it. Construction is the expensive part.
javascripti18n