Skip to content

Instantly share code, notes, and snippets.

@chinchang
Created May 25, 2020 04:13
Show Gist options
  • Save chinchang/0a5d2ba82244ab2ac6314e1a44350094 to your computer and use it in GitHub Desktop.
Save chinchang/0a5d2ba82244ab2ac6314e1a44350094 to your computer and use it in GitHub Desktop.
Handling singular/plural for number units
new Intl.NumberFormat(undefined, {
style: "unit",
unit: 'kilometer',
unitDisplay: 'long'
}).format(10)
//"10 kilometres"
new Intl.NumberFormat(undefined, {
style: "unit",
unit: 'kilometer',
unitDisplay: 'long'
}).format(1)
// "1 kilometre"
new Intl.NumberFormat('hi-EN', {
style: "unit",
unit: 'kilometer',
unitDisplay: 'long'
}).format(1)
// "1 किलोमीटर"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment