note 84780 added to function.round

From: Date: Tue, 29 Jul 2008 23:59:55 +0000
Subject: note 84780 added to function.round
Groups: php.notes 
Request: Send a blank email to php-notes+get-142912@lists.php.net to get a copy of this message
I needed a round up function with precision which surprisingly did not exist (at least that I could see). This does the trick: function roundUp( $value, $precision=0 ) { // If the precision is 0 then default the factor to 1, otherwise // use 10^$precision. This effectively shifts the decimal point to the // right. if ( $precision == 0 ) { $precisionFactor = 1; } else { $precisionFactor = pow( 10, $precision ); } // ceil doesn't have any notion of precision, so by multiplying by // the right factor and then dividing by the same factor we // emulate a precision return ceil( $value * $precisionFactor )/$precisionFactor; } ---- Server IP: 209.41.74.194 Probable Submitter: 66.240.242.254 ---- Manual Page -- http://www.php.net/manual/en/function.round.php Edit -- https://master.php.net/note/edit/84780 Del: integrated -- https://master.php.net/note/delete/84780/integrated Del: useless -- https://master.php.net/note/delete/84780/useless Del: bad code -- https://master.php.net/note/delete/84780/bad+code Del: spam -- https://master.php.net/note/delete/84780/spam Del: non-english -- https://master.php.net/note/delete/84780/non-english Del: in docs -- https://master.php.net/note/delete/84780/in+docs Del: other reasons-- https://master.php.net/note/delete/84780 Reject -- https://master.php.net/note/reject/84780 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#142912) next »