sprintf() oddness

From: Date: Sat, 01 Dec 2007 12:10:19 +0000
Subject: sprintf() oddness
Groups: php.general 
Request: Send a blank email to php-general+get-265348@lists.php.net to get a copy of this message
Why does sprintf( '%.03f', 0.15250000 ) return 0.152 while sprintf( '%.03f', 0.15750000 ) return 0.158? The 4th significant digit in both cases is '5' but in the first case, it's rounded down but in the second case it is rounded up. Is sprintf() basing it's decision on the value of the 3rd significant digit? If so, why? Shouldn't rounding decisions be based on subsequent digits and not preceding ones? I am using PHP 4.3.11 thnx, Christoph

« previous php.general (#265348) next »