note 57329 deleted from function.number-format by danbrown
| From: | danbrown@php.net | Date: | Mon, 20 Jun 2011 15:19:00 +0000 |
| Subject: | note 57329 deleted from function.number-format by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180734@lists.php.net to get a copy of this message | ||
Note Submitter: aj at hotmail dot com
----
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().