I have to print a numeric value which is less than 10 in the following format:
for 0 I want to print it 00
for 1 I want to print it 01
for 2 I want to print it 02
Are there any php library functions which will format numbers in this way?
I have to print a numeric value which is less than 10 in the following format:
for 0 I want to print it 00
for 1 I want to print it 01
for 2 I want to print it 02
Are there any php library functions which will format numbers in this way?
$i = 1;
printf('%02d', $i);
The sprintf
page also documents the syntax for formatting specifiers (%02d
), so you can also see what other options are available.