How to format an integer with zero-padding in TypeScript

1 Answer

0 votes
const number = 283;

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

console.log(formatted);


     
/*
run:
     
"000283" 
     
*/

 



answered Jun 19, 2025 by avibootz

Related questions

1 answer 93 views
1 answer 91 views
1 answer 88 views
1 answer 97 views
1 answer 87 views
1 answer 99 views
...