php: round up and down to nearest cents

by prettyscripts on 2009-09-29 10:22:17

php

use php functions round() to round up or floor() to round down.

generic code, based on examples to round to nearest nickel (5c), dime (10c) and quarter (25c):

PHP:

$x 100 $cents_to_round_to;
$round_up number_format(round($number $x) / $x2);
$round_down number_format(floor($number $x)/ $x2);

Tags: cents, php, rounding

No feedback yet

Leave a comment


Your email address will not be revealed on this site.
PoorExcellent
note: all comments are moderated. do not spam and do not advertise. only comments relevant to the post will be published.
(Line breaks become <br />)
(For my next comment on this site)
(Allow users to contact me through a message form -- Your email will not be revealed!)