Re: sprintf() oddity

From: Date: Tue, 18 Apr 2006 15:47:51 +0000
Subject: Re: sprintf() oddity
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-234189@lists.php.net to get a copy of this message
You are going beyond the number of significant digits PHP can handle so it is truncating beyond that. In the second case it look sstrange, the 12305 ending, but it is probably a 'round' number if you put it in binary, but it turns funny when converted to decimal. In the last example, the precision does not even reach the decimal part. ----- Original Message ----- From: "Chris Boget" <chris.boget@wild.net> To: <php-general@lists.php.net> Sent: Tuesday, April 18, 2006 5:19 PM Subject: [PHP] sprintf() oddity What's going on here: $number = 5000000000.1234567890; echo sprintf( '%.05f', $number ); result: 5000000000.12346 $number = 5000000000000.1234567890; echo sprintf( '%.05f', $number ); result: 5000000000000.12305 $number = 5000000000000000.1234567890; echo sprintf( '%.05f', $number ); result: 5000000000000000.00000 Why isn't it formatting the decimals properly? And apparently losing some? Running PHP 4.3.11 on Windows Server 2003 box. thnx, Chris

« previous php.general (#234189) next »