Skip to content

Instantly share code, notes, and snippets.

@icesernia
Created March 8, 2021 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icesernia/52286b2de088dda9033ac55c4743d2e4 to your computer and use it in GitHub Desktop.
Save icesernia/52286b2de088dda9033ac55c4743d2e4 to your computer and use it in GitHub Desktop.
const number = 123456.789;
console.log(new Intl.NumberFormat('th').format(number)); // expected output: 123,456.789
console.log(new Intl.NumberFormat('en-US', {style: 'unit', unit: 'liter'}).format(number)); // expected output: 123,456.789 L
console.log(new Intl.NumberFormat('en-GB', {style: 'unit', unit: 'liter'}).format(number)); // expected output: 123,456.789 l
console.log(new Intl.NumberFormat('en-US', {style: 'unit', unit: 'byte'}).format(number)); // expected output: 123,456.789 byte
console.log(new Intl.NumberFormat('en-US', { notation: "scientific" }).format(number)); // expected output: 1.235E5
console.log(new Intl.NumberFormat('en-US', { style: 'currency', currency: 'THB' }).format(number));// expected output: THB 123,456.79
console.log(new Intl.NumberFormat('th', { style: 'currency', currency: 'THB' }).format(number)); // expected output: ฿123,456.79
console.log(new Intl.NumberFormat('th-TH-u-nu-thai', { style: 'currency', currency: 'THB' }).format(number)); // expected output: ฿๑๒๓,๔๕๖.๗๙
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment