Re: Problem with number_format

From: Date: Tue, 25 May 2004 14:40:43 +0000
Subject: Re: Problem with number_format
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-186893@lists.php.net to get a copy of this message
From: <fku@freemail.it> > 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. > > Why? > I've noticed this non-coherent approximation behaviour when > 3rd decimal number is 5 and decimals are two many many > times. Isn't there some "rule" where you round up on odd numbers and don't round up on even, otherwise it comes out unevenly rounded up? So 0.15, 0.35, 0.55 will be rounded up to 0.2, 0.4, and 0.6, respectively, whereas 0.25, 0.45, 0.65 will be rounded down to 0.2, 0.4, and 0.6, respectively... Your test cases seem to fit this. ---John Holmes...

« previous php.general (#186893) next »