Skip to content

Instantly share code, notes, and snippets.

@smali-kazmi
Created August 18, 2020 16:47
Show Gist options
  • Save smali-kazmi/a7aac396e3aaa6db87ac95b0538fc5dc to your computer and use it in GitHub Desktop.
Save smali-kazmi/a7aac396e3aaa6db87ac95b0538fc5dc to your computer and use it in GitHub Desktop.
Native JS Number Formatting
var number = 123456.789;
// German uses comma as decimal separator and period for thousands
console.log(number.toLocaleString('de-DE'));
// → 123.456,789
// Arabic in most Arabic speaking countries uses Eastern Arabic digits
console.log(number.toLocaleString('ar-EG'));
// → ١٢٣٤٥٦٫٧٨٩
// India uses thousands/lakh/crore separators
console.log(number.toLocaleString('en-IN'));
// → 1,23,456.789
// the nu extension key requests a numbering system, e.g. Chinese decimal
console.log(number.toLocaleString('zh-Hans-CN-u-nu-hanidec'));
// → 一二三,四五六.七八九
// when requesting a language that may not be supported, such as
// Balinese, include a fallback language, in this case Indonesian
console.log(number.toLocaleString(['ban', 'id']));
// → 123.456,789
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment