开发者

printing a float with fixed size of 0

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜