note 114122 added to function.round

From: Date: Mon, 13 Jan 2014 11:28:21 +0000
Subject: note 114122 added to function.round
Groups: php.notes 
Request: Send a blank email to php-notes+get-198225@lists.php.net to get a copy of this message
I discovered that under some conditions you can get rounding errors with round when converting the number to a string afterwards. To fix this I swapped round() for number_format(). Unfortunately i cant give an example (because the number cant be represented as a string !) essentially I had round(0.688888889,2); which would stay as 0.68888889 when printed as a string. But using number_format it correctly became 0.69. ---- Server IP: 87.117.229.81 Probable Submitter: 82.69.6.162 ---- Manual Page -- http://php.net/manual/en/function.round.php Edit -- https://master.php.net/note/edit/114122 Del: integrated -- https://master.php.net/note/delete/114122/integrated Del: useless -- https://master.php.net/note/delete/114122/useless Del: bad code -- https://master.php.net/note/delete/114122/bad+code Del: spam -- https://master.php.net/note/delete/114122/spam Del: non-english -- https://master.php.net/note/delete/114122/non-english Del: in docs -- https://master.php.net/note/delete/114122/in+docs Del: other reasons-- https://master.php.net/note/delete/114122 Reject -- https://master.php.net/note/reject/114122 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198225) next »