PHP - Number: Padding Numbers with ZeroesTag: number, padding Category: PHP Basicpost: 16 Mar 2008 read: 56 PHP Number Tips - Part 7: If you want to format a number with leading or trailing zeroes, you can use the printf( ) or sprintf( ) function with appropriate format specifiers such as:
PHP's printf( ) and sprintf( ) functions are very similar to the printf( ) and sprintf( ) functions. Both functions accept two arguments, a series of format specifiers and the raw string or number to be formatted. The input is then formatted according to the format specifiers and the output is either displayed with printf( ) or assigned to a variable with sprintf( ).
You can also combine these field templates with numbers that indicate the number of digits to display for example: %1.2f. It implies that only two digits should be displayed after the decimal point and adding 0 as the padding specifier that tells about the function to zero-pad the numbers to the specified length. Beside that, you can use an alternative padding character by prefixing it with a single quote ( ' ). |
| | Give Your Opinion | Recommend |
|

