Reputation: 105
I want to round (up or down) prices to nearest $xx.99
For example:
$17.99 -> Stay as is
$22.03 -> $21.99
$33.85 -> $33.99
$45 -> $44.99
Upvotes: 3
Views: 2790
Reputation: 8214
Add 0.01, round, minus 0.01
$input = 17.99; // example input
$add = $input + 0.01;
$round = round($add);
$output = $round - 0.01;
Or all-in-one:
return round($input + 0.01) - 0.01;
Upvotes: 13