Skip to content

Commit

Permalink
feat: localize number formatting based on user browser settings
Browse files Browse the repository at this point in the history
  • Loading branch information
robhyrk committed Jun 4, 2024
1 parent 7c8c1e8 commit f0f67c3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/util/format-compact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ export const formatNumberCompact = (
num: number | bigint,
maximumSignificantDigits = 3,
) => {
const userLocale = navigator.language || "en-US";
// Ensure displaying absolute zeros are unsigned(-), because javascript sucks sometimes.
if (num === 0 || num === 0n) num = 0;

return new Intl.NumberFormat("en-US", {
return new Intl.NumberFormat(userLocale, {
maximumSignificantDigits: maximumSignificantDigits,
notation: "compact",
}).format(num);
Expand Down

0 comments on commit f0f67c3

Please sign in to comment.