Showing posts with label Number format. Show all posts
Showing posts with label Number format. Show all posts

Wednesday 25 June 2014

PHP number format 4 digits [duplicate]

Method I

echo str_pad( "3", 4, "0", STR_PAD_LEFT );
Input $s_number = "3"; Output: 0003

Method II

$s_number = '12';
printf("%04d", $s_number);
Input $s_number = "12"; Output: 0012