将价格四舍五入到最接近的 $xx.99


Round prices to nearest $xx.99

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

例如:

$17.99 -> Stay as is
$22.03 -> $21.99
$33.85 -> $33.99
$45 -> $44.99

加 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;