将浮点数格式化为两位小数 [英] Format a float to two decimal places
本文介绍了将浮点数格式化为两位小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将浮点值格式化为两位小数.
I want to format a float value I have to two decimal places.
例如,如果我有一个价格为 5.2
的浮点数,我希望它的格式为 5.20
.
For example if I have a float for a price of 5.2
, I want it to be formatted as 5.20
.
推荐答案
试试 number_format
:
echo number_format("5.2",2)
这篇关于将浮点数格式化为两位小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文