#19189 [Opn->Bgs]: sprintf yields wrong result

From: Date: Fri, 30 Aug 2002 08:47:59 +0000
Subject: #19189 [Opn->Bgs]: sprintf yields wrong result
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-18232@lists.php.net to get a copy of this message
ID: 19189 Updated by: derick@php.net Reported By: gwenzel@emb.de -Status: Open +Status: Bogus Bug Type: Variables related Operating System: Linux Suse 7.1 PHP Version: 4.2.0 New Comment: Because 68.85 * 100 is about 6885 (perhaps it is 6884.999999999991). See also: http://www.php.net/manual/en/print/language.types.float.php and maybe changing your precision helps: http://www.php.net/manual/en/configuration.php#ini.precision Derick Previous Comments: ------------------------------------------------------------------------ [2002-08-30 04:43:42] gwenzel@emb.de Ok. This might not be a bug in sprintf. But why does echo ( 68.85*100 ) yield 6885 and echo ( intval ( 68.85*100 ) ) yield 6884 ? And by the way my provider does not support PHP with the bcmath extension ------------------------------------------------------------------------ [2002-08-30 04:43:41] gwenzel@emb.de Ok. This might not be a bug in sprintf. But why does echo ( 68.85*100 ) yield 6885 and echo ( intval ( 68.85*100 ) ) yield 6884 ? And by the way my provider does not support PHP with the bcmath extension ------------------------------------------------------------------------ [2002-08-30 03:32:51] sander@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Use the bcmath extension to avoid problems like these. ------------------------------------------------------------------------ [2002-08-30 03:20:42] gwenzel@emb.de echo ( sprintf("%012d", 68.85*100 ) ); yields 000000006884 Strangly enough: echo ( sprintf("%012d", 68.95*100 ) ); yields the correct result: 000000006895 './configure' '--with-apxs=/usr/local/apache/bin/apxs' '--enable-trans-sid' '--with-mysql' '--enable-ftp' '--with-config-file-path=/www/conf' '--with-zlib-dir=/usr/local' '--with-gd=/usr/local' '--with-png-dir=/usr/local' '--with-jpeg-dir=/usr/local' '--with-freetype-dir=/usr/local' ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=19189&edit=1

« previous php.bugs (#18232) next »