Give Me Cake

CakePHP Baking, Internet Marketing, SEO, Design and more

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;&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 ;)

Useful Web Application Interface Techniques

Posted on | February 1, 2009 | No Comments

Smashing Magazine has this great article on web application interface. This could be applied in Cakephp HtmlHelper or by extending HtmlHelper to provide customised interface html codes for your application.

http://www.smashingmagazine.com/2009/01/12/10-useful-web-application-interface-techniques/

  • Give me Cake?

    Givemecake.dev-work.com a collection of web application development tips, tutorials and resources.
  • See Your Ads Here

  • See Your Ads Here

  • Meta