Consider i ha开发者_运维百科ve this number:
0.012
0.1
0.04
0.0011
i need them to have always 4 digits after .
Example:
0.0120
0.1000
0.0400
0.0011
Should i use printf?
%f1.4?
%.4f
is what you're looking for.
The following will output the number to standard output or the web page:
printf("%.4f", $number);
Or if you want to dump it to a string:
$str = sprintf("%.4f", $number);
精彩评论