PHP 4.0 Bug #9248 Updated: float,int multiplication problem when using sprintf

From: Date: Tue, 13 Feb 2001 23:45:55 +0000
Subject: PHP 4.0 Bug #9248 Updated: float,int multiplication problem when using sprintf
Groups: php.dev 
Request: Send a blank email to php-dev+get-46529@lists.php.net to get a copy of this message
ID: 9248 Updated by: andre Reported By: mike@meltmedia.com Old-Status: Closed Status: Bogus Bug Type: Math related Assigned To: Comments: bogus Previous Comments: --------------------------------------------------------------------------- [2001-02-13 18:35:22] hholzgra@php.net its the good old binary/decimal rounding issue $result is internally something like e.g.14497.999999999998 when using plain echo rounding will be applied (see php.ini 'precision') while sprintf "%d" does not round but will cut of all decimals sprintf("%d",round($result)) should work find --------------------------------------------------------------------------- [2001-02-13 18:21:22] mike@meltmedia.com Sometimes when trying to multiply a float and a int then print the result out with sprintf there is a error in the computation. The following code produces the incorrect output: <? $val1 = 144.98; $result = ($val1 * 100); echo $result . "n"; ## Correct output '14498' echo sprintf ("%10dn", $result); ## Incorrect output '14497' ?> Not sure if there is something obvious that I am missing? Any help would be appreciated. My config line: ./configure --with-mysql=/usr --with-apxs=/usr/sbin/apxs --with-gd=/usr/local --enable-trans-sid --enable-track-vars --enable-bcmath --with-ttf --------------------------------------------------------------------------- ATTENTION! Do NOT reply to this email! To reply, use the web interface found at http://bugs.php.net/?id=9248&edit=2

« previous php.dev (#46529) next »