开发者

PHP precision rounding question

开发者 https://www.devze.com 2023-04-07 16:10 出处:网络
Wanted to as a simple question. Code: $myarray = array(5.0000); echo round($myarray[0],2); 开发者_如何学编程

Wanted to as a simple question.

Code:

$myarray = array(5.0000);
echo round($myarray[0],2);
开发者_如何学编程

Ouput:

5

Why is the output 5 and not 5.00 ?

Thanks


It doesn't show the 0's after the decimal point if there are only 0's.

5.050 would be shown as 5.05...

you can have a look at the number_format function if you want to show the 0's.


It's because round actually rounds off the data you give to it, it doesn't change how that data is printed.

If you want to specify how the data is output, look into using printf, such as:

printf ("%.2f\n", $myarray[0]);
0

精彩评论

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

关注公众号