note 106818 added to function.round

From: Date: Thu, 08 Dec 2011 23:41:05 +0000
Subject: note 106818 added to function.round
Groups: php.notes 
Request: Send a blank email to php-notes+get-184987@lists.php.net to get a copy of this message
Rounding decimal points <?php function rfloor($real,$decimals = 2) { return substr($real, 0,strrpos($real,'.',0) + (1 + $decimals)); } function rceil($real,$decimals = 2) { $newreal = substr($real, 0,strrpos($real,'.',0) + (1 + $decimals)); if($real[strlen($newreal)] > 0) { $newreal[strlen($newreal) - 1] += 1; } return $newreal; } function rround($real,$decimals = 2,$halfdown = FALSE) { $newreal = substr($real, 0,strrpos($real,'.',0) + (1 + $decimals)); if(($halfdown == FALSE) && ($real[strlen($newreal)] = 5)) { $newreal[strlen($newreal) - 1] += 1; } else if($real[strlen($newreal)] > 5) { $newreal[strlen($newreal) - 1] += 1; } return $newreal; } ?> Usage: rceil(12.12146321,2); //12.13 -- as long as the value is greater than 0, round up. rfloor(12.12946321,2); //12.12 -- drop everything after the number of decimal places rround(12.12546321,2); //12.13 -- round half up rround(12.12546321,2,TRUE); //12.12 -- round half down ---- Server IP: 69.147.83.197 Probable Submitter: 209.49.41.67 ---- Manual Page -- http://www.php.net/manual/en/function.round.php Edit -- https://master.php.net/note/edit/106818 Del: integrated -- https://master.php.net/note/delete/106818/integrated Del: useless -- https://master.php.net/note/delete/106818/useless Del: bad code -- https://master.php.net/note/delete/106818/bad+code Del: spam -- https://master.php.net/note/delete/106818/spam Del: non-english -- https://master.php.net/note/delete/106818/non-english Del: in docs -- https://master.php.net/note/delete/106818/in+docs Del: other reasons-- https://master.php.net/note/delete/106818 Reject -- https://master.php.net/note/reject/106818 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184987) next »