PHP, Format Number to have always have 2 decimal places

空扰寡人 提交于 2019-12-04 03:24:23

问题


In PHP I have decimal numbers that may or may not have trailing zeros.

For example

 1
 1.1
43.87

How do I make sure that all these numbers have exactly two decimal places like this:

 1.00
 1.10
43.87

回答1:


You should use number_format():

number_format(1.1, 2);


来源:https://stackoverflow.com/questions/18898638/php-format-number-to-have-always-have-2-decimal-places

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