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 83 views
1 answer 79 views
1 answer 74 views
1 answer 84 views
1 answer 75 views
1 answer 85 views
...