我有一个积分系统到位,目前,一个客户得到分配的积分和每500个积分,他们得到一个国标5的凭单。
目前,这是我有,如果有人在900分,然后输出显示,他们已经赢得了10英镑,这是不正确的。我怎么才能舍身,所以它只会显示10 5,然后当他们得到超过1000分,它将显示10 10等。
<?php if($total >= 500) {
$voucher_count = $total / 500;
$voucher_rounded = round($voucher_count, 0) . "<br />";
$voucher_total = $voucher_rounded * 5; ?>
<p class="earnings-to-date">You've earned £<?php echo $voucher_total; ?> so far</p>
<?php } ?>发布于 2019-12-02 11:20:42
在除以500之前,只需使用模运算符(%)过滤掉额外的400 (或其他什么):
$total = 900;
if($total >= 500) {
$voucher_count = ($total - $total % 500) / 500;
$voucher_total = $voucher_count * 5;
echo $voucher_total;
}输出:
5模运算符用指定的数计算除法的剩余部分。在这种情况下:
($total - $total % 500) / 500;计算余数($total % 500 = 400),从$total中减去它,然后用500除以。
发布于 2019-12-02 11:25:01
地板圆周分数下降
https://www.php.net/manual/en/function.floor.php
$total = 900;
if($total >= 500) {
$voucher_count = $total / 500;
$voucher_rounded = floor($voucher_count);
$voucher_total = $voucher_rounded * 5;
echo $voucher_total; // Output: 5
}发布于 2019-12-02 11:28:27
只需使用floor
$voucher_total = round(floor($total/500)) * 5;https://stackoverflow.com/questions/59137841
复制相似问题