PHP,格式编号总是有 2 个小数位 [英] PHP, Format Number to have always have 2 decimal places
本文介绍了PHP,格式编号总是有 2 个小数位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 PHP 中,我有十进制数字,可能有也可能没有尾随零.
In PHP I have decimal numbers that may or may not have trailing zeros.
例如
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
推荐答案
你应该使用 number_format():
number_format(1.1, 2);
这篇关于PHP,格式编号总是有 2 个小数位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文