Round prices to nearest $xx.99

☆樱花仙子☆ 提交于 2019-12-23 15:43:29

问题


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

回答1:


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;


来源:https://stackoverflow.com/questions/35129514/round-prices-to-nearest-xx-99

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!