开发者

printing a float with fixed size of 0

开发者 https://www.devze.com 2023-02-16 01:24 出处:网络
Consider i ha开发者_运维百科ve this number: 0.012 0.1 0.04 0.0011 i need them to have always 4 digits after .

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

精彩评论

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