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 85 views
1 answer 81 views
1 answer 77 views
1 answer 86 views
1 answer 77 views
1 answer 87 views
...