Format number with leading zero

By | September 2, 2017

Format number with leading zero

You are having some number which should contain eight digits in it as the registration number. So for the first registration, the number should be 00000001 and for the next 00000002, similarly 00012456, 00002158, 01234568, 25634897 and so on till 99999999. To achieve this we need to format a number with leading zeroes as shown below,

To format a number with leading zero in PHP, we can use two methods,
1. sprintf()
2. str_pad()
to format a number to have exactly 4 numbers

 

Leave a Reply