DEV Community

Mehul Lakhanpal
Mehul Lakhanpal

Posted on • Originally published at codedrops.tech

Pretty format numbers

const length = 5;
const amount = [23, 435, 34.34, 234.3];

amount.forEach(num => {
    const paddedNum = String(num).padStart(length, '0');
    console.log(paddedNum);
});

/* 
Output:
00023
00435
34.34
234.3
*/

Enter fullscreen mode Exit fullscreen mode

Thanks for reading 💙

Follow @codedrops.tech for daily posts.

InstagramTwitterFacebook

Micro-Learning ● Web Development ● Javascript ● MERN stack ● Javascript

codedrops.tech

Top comments (0)