PHP 4.0 Bug #10002: sprintf() and floating point
| From: | bmr at comtime dot com | Date: | Mon, 26 Mar 2001 19:13:27 +0000 |
| Subject: | PHP 4.0 Bug #10002: sprintf() and floating point | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-49972@lists.php.net to get a copy of this message | ||
From: bmr@comtime.com
Operating system: RedHat 7.0
PHP version: 4.0 Latest CVS (26/03/2001)
PHP Bug Type: Strings related
Bug description: sprintf() and floating point
<?php
printf('%.2f',0.09999999999999999167332731531132594682276248931884765625);
?>
produces '0.0:' instead of '0.10'
I'm really curious as to why PHP just doesn't use libc's sprintf().
./configure --with-oracle=/usr/local/oracle/product/8.1.7 \
--with-oci8=/usr/local/oracle/product/8.1.7 --enable-force-cgi-redirect \
--enable-track-vars --with-posix --enable-sockets --enable-sigchild \
--with-gd=/usr/local
gcc version 2.95.2 19991024 (release)
This is not exactly a fix...
--- ext/standard/formatted_print.c Mon Mar 26 14:01:31 2001
+++ ext/standard/formatted_print.c-fixed Mon Mar 26 14:02:26 2001
@@ -92,7 +92,7 @@
while (p1 < &cvt_buf[NDIG])
*p++ = *p1++;
} else if (arg > 0) {
- while ((fj = arg * 10) < 1) {
+ while ((fj = arg * 10.0) < 0.9999999) {
arg = fj;
r2--;
}
--
Edit Bug report at: http://bugs.php.net/?id=10002&edit=1