Re: Problem with number_format
| From: | Martin Geisler | Date: | Tue, 25 May 2004 14:57:09 +0000 |
| Subject: | Re: Problem with number_format | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-186898@lists.php.net to get a copy of this message | ||
fku@freemail.it writes:
> please suppose PHP 4.3.2 and $number=502,3550
>
> number_format($number,2,'.',' ') returns 502.36.
>
> It seems ok, but if $number=253,0650
>
> number_format($number,2,'.',' ') returns 253.06 instead of 253.07.
My PHP manual (from a Debian package) has the following note on the
page for round():
Caution
When rounding on exact halves round() rounds down on evens and up on
odds. If you want to always force it in one direction on a .5 (or
.05 in your case) add or substract a tiny fuzz factor. The reason
behind rounding half the values down and the other half up is to
avoid the classical banking problem where if you always rounded down
you would be stealing money from your customers, or if you always
rounded up you would end up over time losing money. By averaging it
out through evens and odds you statistically break even.
--
Martin Geisler My GnuPG Key: 0xF7F6B57B
PHP EXIF Library | PhpWeather | PhpShell
http://pel.sf.net/ | http://phpweather.net/ | http://gimpster.com/
Read/write EXIF data | Show current weather | A shell in a browser