$result = number_format($x, 2, '.', ','); //Will do the following correctly
115255 = 115,225.00
115255.4 = 115,225.40
115255.40 = 115,225.40
115255.455 = 115,255.46
但是当用户在小数点后输入超过 2 位时,我需要,而不是将它们仅切成 2 位小数并按原样使用它......
115255.455 = 115,255.455
115255.4557 = 115,255.4557
我可以做这样的事情吗?
if($x == number_format($x, 3)) //I will do it in while loop later, lets test 3 now
$result = number_format($x, 3, '.', ',');
else $result = number_format($x, 2, '.', ',');
前面的 if 条件永远不会起作用,否则只会起作用