-1

我正在使用我的数据库中的数据来填写报告中的 td 我的数据是这样的

200,400,250.15,251.10,0.10,0.1,12510.12 and 1524

我想要一种显示这样的数据的方法

200.00,400.00,250.00,15.00,251.10,0.10,0.10,12510.12 AND 1524,00

我希望在“。”之后添加 00。数字大小可互换

有没有办法做到这一点 ?我在用

$cost<= str_pad($cost, 5, ",00", STR_PAD_RIGHT); 

但它没有做我想要的。谢谢您的帮助

4

5 回答 5

1

尝试使用sprintf

echo sprintf("%0.2f", $num);
于 2013-10-04T13:20:15.857 回答
1

使用Number_format函数

 echo number_format($number,2,',',' ');
于 2013-10-04T13:21:13.550 回答
1

对于您的情况,请使用number_formatsetup $dec_pointto,$thousands_septo .

前任。

$nombre_format_francais = number_format($number, 2, ',', '.');

参考: http: //php.net/manual/en/function.number-format.php

于 2013-10-04T13:22:21.887 回答
0

用于number_format($cost,2)使变量落后 .00

于 2013-10-04T13:20:48.143 回答
0

它很简单..您可以使用 number_format()

例如

number_format($cost, 2); 
于 2013-10-04T13:21:06.710 回答