圆形价格最接近$ xx.99

时间:2016-02-01 11:35:07

标签: php rounding

我想将价格四舍五入(上涨或下跌)至最接近的$ xx.99

例如:

$17.99 -> Stay as is

$22.03 -> $21.99

$33.85 -> $33.99

$45 -> $44.99

1 个答案:

答案 0 :(得分:10)

加0.01,圆,减0.01

$input = 17.99; // example input
$add = $input + 0.01;
$round = round($add);
$output = $round - 0.01;

或一体化:

return round($input + 0.01) - 0.01;