Is there any benefit to include the length specifier in a format string for sprintf or printf even though it’s not mentioned in the PHP manual:
h– The argument is interpreted as a short int or unsigned short int (only applies to integer specifiers:i,d,o,u,xandX).l– The argument is interpreted as a long int or unsigned long int for integer specifiers (i,d,o,u,xandX), and as a wide character or wide character string for specifierscands.L– The argument is interpreted as a long double (only applies to floating point specifiers:e,E,f,gandG).
Or is it better to leave it out? I guess what I’m trying to figure out is why php decided to leave it out.
Consider the following code, which comes from phpriot.com:
$a = 0.5;
$b = 0.1;
$c = 16;
echo sprintf('%01.2lf %.1lf 0x%x', $a, $b, $c); # 0.50 0.1 0x10
In PHP there are no differentiation between numbers except for Integers and Floats. Depending on system architecture, 32 or 64-bit, the Integer type is a int or int64. You can use strings and BCMath to imitate larger numbers, but they’ll always be stored in strings.
So in PHP there’s no purpose to have a length specifier to change the type of the number. Either it’s a float, or it’s not.