How to format an integer with zero-padding in Node.js

1 Answer

0 votes
const number = 893;

// Format with leading zeros (6 digits total)
const formatted = number.toString().padStart(6, '0');

console.log(formatted);


     
/*
run:
     
000893
     
*/

 



answered Jun 19, 2025 by avibootz

Related questions

...