note 17598 added to function.round

From: Date: Sun, 16 Dec 2001 18:36:38 +0000
Subject: note 17598 added to function.round
Groups: php.notes 
Request: Send a blank email to php-notes+get-22925@lists.php.net to get a copy of this message
I'm currently writing a financial app in PHP which needs 100% precision.. however, a really accurate (and version independant, see above) rounding function was missing, so I quickly wrote this one which does the job perfectly. Thought I'll share it with you. function bcround ($number, $decimals) { return(bcadd (bcadd ($number,"0.".str_repeat("0",$decimals)."5", $decimals+1), 0, $decimals)); } Enjoy and feel free to use it (fully at your own risk ;-). - Felix Schwarz, Innovative -- http://www.php.net/manual/en/function.round.php http://master.php.net/manage/user-notes.php?action=edit+17598 http://master.php.net/manage/user-notes.php?action=delete+17598 http://master.php.net/manage/user-notes.php?action=reject+17598

« previous php.notes (#22925) next »