note 57329 added to function.number-format

From: Date: Fri, 30 Sep 2005 16:18:32 +0000
Subject: note 57329 added to function.number-format
Groups: php.notes 
Request: Send a blank email to php-notes+get-96058@lists.php.net to get a copy of this message
In responce to astrolox; This is because the numbers generated by performing math are double precision (which means pretty darn accurate) and not perfect precision (which would be what you get when you do the math on paper). For example 483.00 * 0.175 equals 84.525 on paper, but the computer can't do math with perfect precision and ends up with something like 84.52499999... If dealing with money the best practice is to perform round() on your floating point numbers and always round up to the nearest cent, or add something small like .000001 before using number_format(). Personally I prefer to round(). ---- Manual Page -- http://www.php.net/manual/en/function.number-format.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57329 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57329&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57329&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57329&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57329&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57329&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57329&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57329&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57329&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#96058) next »