Closed ivan-aksamentov closed 4 years ago
Web standard Intl.NumberFormat would be good. Probably { notation: "compact" , compactDisplay: "short" }
.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
const number = 12345678910;
console.log(new Intl.NumberFormat('en-GB', { notation: "compact" , compactDisplay: "short" }).format(number));
console.log(new Intl.NumberFormat('en-GB', { notation: "compact" , compactDisplay: "long" }).format(number));
console.log(new Intl.NumberFormat('de-DE', { notation: "compact" , compactDisplay: "short" }).format(number));
console.log(new Intl.NumberFormat('de-DE', { notation: "compact" , compactDisplay: "long" }).format(number));
console.log(new Intl.NumberFormat('ru-RU', { notation: "compact" , compactDisplay: "short" }).format(number));
console.log(new Intl.NumberFormat('ru-RU', { notation: "compact" , compactDisplay: "long" }).format(number));
Gives:
> "12B"
> "12 billion"
> "12 Mrd."
> "12 Milliarden"
> "12 ะผะปัะด"
> "12 ะผะธะปะปะธะฐัะดะพะฒ"
As @rcbevans points out in #210, this issue is not fixed and the 'humanized' totals are overly rounded!
๐ Feature Request
Now that the numbers are displayed in a human-readable form, would be nice to also make them internationalized.
๐ฆ Context
๐ฏ Describe the feature
It is hard to describe all the requirements specifically, without knowing the languages. This should be covered by a library.
๐ป Examples
Here is an non-exhaustive list of requirements:
๐ Possible Solution
A mature library should be used. Either D3.js currently used or number formatting, or react-i18next used for i18n or both.
Related: