note 76923 added to function.round

From: Date: Mon, 06 Aug 2007 01:39:53 +0000
Subject: note 76923 added to function.round
Groups: php.notes 
Request: Send a blank email to php-notes+get-129197@lists.php.net to get a copy of this message
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 :-) ---- Server IP: 203.202.10.60 Probable Submitter: 150.101.78.89 ---- Manual Page -- http://www.php.net/manual/en/function.round.php Edit -- https://master.php.net/note/edit/76923 Del: integrated -- https://master.php.net/note/delete/76923/integrated Del: useless -- https://master.php.net/note/delete/76923/useless Del: bad code -- https://master.php.net/note/delete/76923/bad+code Del: spam -- https://master.php.net/note/delete/76923/spam Del: non-english -- https://master.php.net/note/delete/76923/non-english Del: in docs -- https://master.php.net/note/delete/76923/in+docs Del: other reasons-- https://master.php.net/note/delete/76923 Reject -- https://master.php.net/note/reject/76923 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129197) next »