Rounding down to the nearest $0.05
Posted on | February 9, 2009 | No Comments
Updated: Found a shortcut to round down to the nearest $0.05.
round(20 * $amount, 0) / 20 will give you the amount round to the nearest $0.05
More rounding functions can be found at Microsoft Access tips: Rounding numbers in Access.
Singapore has decided not to mint anymore 1 cent coins. Likely the reason is because minting 1 cent coins is more costly than the surface value of the coin. So what happen when we have to pay for something costing $1.09? It is round down to nearest 5 cents. $1.05 should be tendered. What about $1.04? It should be rounded down to $1.00
This is how it will be calculated in PHP.
<?php
$amount_due = $payment['Payment']['amount'] + $payment['Payment']['gst'];
$rounded = round($amount_due, 1) - round($amount_due, 2);
if($rounded > 0.05) {
$amount_due = $amount_due - ($rounded - 0.05);
}
if($rounded > 0.01 &amp;&amp; $rounded < 0.05) {
$amount_due = $amount_due - ($rounded);
}
$round_down = $rounded - 0.05;
echo $number->currency($round_down, '$')
?>
This is just the calculation process if I would to do it mentally, it is NOT tested for all possible mathematical errors. Note that I am not an accountant
Comments
Leave a Reply




















