number_format中的number_format不起作用

Fra*_*ank 1 php number-formatting

我在php中使用一个很小的代码时遇到了麻烦:

$price = 135;
$price_sale = number_format($price * 0.75,2,',','');
//*returns 101,25 *//
$count_products = 3;
$new_price = number_format($price_sale * $count_products,2,',','');
//* returns 303,00 and not 303,75 *//
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

问候,

坦率

Ign*_*ams 8

将数字保留为数字.在输出阶段之前不要格式化.


Pek*_*ica 5

永远不要number_format对要进行计算的数字做.

101,25 不是PHP中的有效数字.

使用原始值直到输出数字.然后,做一个number_format().