Re: sprintf() oddity

From: Date: Tue, 18 Apr 2006 15:26:19 +0000
Subject: Re: sprintf() oddity
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-234185@lists.php.net to get a copy of this message
Chris Boget wrote:
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 Because you can either work with large Numbers before point or after.
both doesn't work. And on top of that, PHP works intern with double typed vars. That's causing the problem here. probably round() and number_format() will have better outcomes. Test that :) -- Smileys rule (cX.x)C --o(^_^o) Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

« previous php.general (#234185) next »