Php 数字格式中的数字格式不';行不通

Php 数字格式中的数字格式不';行不通,php,number-formatting,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 *// 我如何解决这个问题 问候, 弗兰

我在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 *//
我如何解决这个问题

问候,


弗兰克

将数字保留为数字。直到输出阶段才进行格式化。

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

永远不要对要进行计算的数字进行格式化

101,25
在PHP中不是有效数字


使用原始值,直到输出数字。然后,对要进行计算的数字执行
number\u format()

绝不执行
number\u format

101,25
在PHP中不是有效数字

使用原始值,直到输出数字。然后,执行
number\u format()

使用:

$new_price = number_format($price * 0.75 * $count_products,2,',','');
因为
$price\u sale
是一个
字符串
,在类型转换后,可能不会有您正在计算的值。(参见:)

使用:

$new_price = number_format($price * 0.75 * $count_products,2,',','');

因为
$price\u sale
是一个
字符串
,在类型转换后,可能不会有您正在计算的值。(请参阅:)

好的,谢谢!我真傻。不知道最后必须输出数字格式。好的,谢谢!我真傻。不知道最后必须输出数字格式。