PHP - number_format and rounding

大城市里の小女人 提交于 2019-12-20 07:22:39

问题


The number_format function in PHP seems to round by default. My understanding is that this function is useful for separating every three numbers with a comma. Like 1403423 becomes 1,404,423 when using number_format.

So, if I have a large number that I want rounded to two decimal places, how can I do this and still have the commas properly displayed?

Desired behavior: 12042.529 --> 12,042.53


回答1:


$a=12042.529;
echo number_format($a,2,'.',',');


来源:https://stackoverflow.com/questions/19019409/php-number-format-and-rounding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!