note 76923 deleted from function.round by googleguy

From: Date: Sun, 09 Dec 2012 08:24:25 +0000
Subject: note 76923 deleted from function.round by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192421@lists.php.net to get a copy of this message
Note Submitter: mark at customcartons dot com dot au ---- I'm sure its been done before, but here's my example of a round up function. This function allows you to specify the number of decimal places to round up to. Eg, when rounding up to 3 decimal places, this function adds 0.0005 to the original value and performs round(), or for 6 decimal places, adds 0.0000005 and performs round(), etc... Hopefully some of you will find it useful: <?php function roundup ($value, $dp) { // Offset to add to $value to cause round() to round up to nearest significant digit for '$dp' decimal places $offset = pow (10, -($dp + 1)) * 5; return round ($value + $offset, $dp); } ?> Please post if you have any comments or improvements on this :-)

« previous php.notes (#192421) next »