Skip to main content

Command Palette

Search for a command to run...

Pretty format number using '.toLocaleString()'

Published
1 min readView as Markdown
// Error
console.log(123456.toLocaleString()); // wont work

// Method 1: Store it in a variable 
const n = 123456;
console.log(n.toLocaleString()); // 123,456

// Method 2: Use Number() to convert it into type Number
console.log(Number(12345).toLocaleString()); // 12,345

More from this blog

Codedrops.tech

49 posts