我在购物车表中存储了一个价格,并试图找到一种方法,当价格除以 3 或任何其他奇数时调整 1 美分。
$cost = '1';
$split = '3';
$check1 = $cost/$split; // .33
$check2 = $cost/$split; // .33
$check3 = $cost/$split; // this should give .34
如何调整差异?
最佳答案
好的,如果您想要无限的 $checks
并且只让最后一个 $check
包含其余部分,您可以执行以下操作:
<?php
$cost=1;
$split=3;
$q=round($cost/$split,2);
$r=$cost-($split*$q);
$firstchecks=$q;
$lastcheck=$q+$r;
?>
关于php - 将 1 美元除以 3 并调整 1 美分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29882806/