From: Antony Dovgal Date: Thu, 19 Apr 2007 09:30:49 +0000 (+0000) Subject: fix double-to-string conversion utils X-Git-Tag: php-5.2.2RC2~46 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9ad2c80c62246ccf79a3eb044a67958dde0e281e;p=php fix double-to-string conversion utils --- diff --git a/Zend/tests/double_to_string.phpt b/Zend/tests/double_to_string.phpt new file mode 100644 index 0000000000..e6c66e2530 --- /dev/null +++ b/Zend/tests/double_to_string.phpt @@ -0,0 +1,48 @@ +--TEST-- +double to string conversion tests +--FILE-- + +--EXPECTF-- +string(7) "2.9E+17" +string(7) "2.9E+14" +string(14) "29000000000000" +string(14) "29000000000000" +string(14) "29000000000001" +string(13) "29000.7123123" +string(15) "239234242.71231" +string(16) "0.12345678901235" +string(14) "10000000000000" +string(7) "1.0E+14" +string(7) "1.0E+18" +string(7) "1.0E+14" +string(11) "10000000000" +string(7) "1.0E+15" +string(7) "1.0E+16" +string(1) "0" +Done diff --git a/Zend/zend_strtod.c b/Zend/zend_strtod.c index 798d94a384..94d1383aa2 100644 --- a/Zend/zend_strtod.c +++ b/Zend/zend_strtod.c @@ -1707,7 +1707,14 @@ ZEND_API char * zend_dtoa(double _d, int mode, int ndigits, int *decpt, int *sig if (value(d) > 0.5 + value(eps)) goto bump_up; else if (value(d) < 0.5 - value(eps)) { - while(*--s == '0'); + /* cut ALL traling zeros only if the number of chars is greater than precision + * otherwise cut only extra zeros + */ + if (k < ndigits) { + while(*--s == '0' && (s - s0) > k); + } else { + while(*--s == '0'); + } s++; goto ret1; }