本文介绍了PHP number_format()十进制.99变为.00的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将脏"数字转换为正确书写的货币价格.输入数字将类似于23.99000,我要显示23,99 +欧元符号.
I want to turn a "dirty" figure into a properly written currency price.The input figure will be something like 23.99000 and I want to display 23,99 + the Euro symbol.
我用这个:
$price = number_format($price, 2, ',', '')." €";
但是结果将是23,00€,而不是23,99€.
But the result will be 23,00 € instead of 23,99 €.
我怎么了?谢谢!
推荐答案
尝试如下操作:
<?php
$price = 23.99000;
$price = sprintf("%01,2f", $price).' €';
echo $price;
输出:
23,99 €
f
表示它将字符串视为浮点型,并相应地进行格式化.
the f
means it'll treat the string as a float, and format accordingly.
这篇关于PHP number_format()十进制.99变为.00的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!