DEV Community


Pretty format number using '.toLocaleString()'

Mehul Lakhanpal
Full stack Developer | Micro-blogging on Web Development at | Creator of File Ops, Note Box, GitHub Marker
Originally published at ・1 min read
// 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
Enter fullscreen mode Exit fullscreen mode

Thanks for reading 💙

Follow for more.


Micro-Learning ● Web Development ● Javascript ● MERN stack


File Ops - A VS Code extension to easily tag/alias files & quick switch between files

Discussion (0)

Forem Open with the Forem app