diff options
author | Wez Furlong <wez@php.net> | 2003-01-10 13:32:24 +0000 |
---|---|---|
committer | Wez Furlong <wez@php.net> | 2003-01-10 13:32:24 +0000 |
commit | cf9f784ecd8c6a4a2c4d5fb2fa519d91569480c6 (patch) | |
tree | 743736df4791be46a7a1f6bb121f7359878a3b8a /ext/standard | |
parent | 0988bc2ee62e5407a8271eb93f4140a85bf6df2a (diff) | |
download | php-git-cf9f784ecd8c6a4a2c4d5fb2fa519d91569480c6.tar.gz |
Fix the number format fix when the number of decimal places is 0.
# Thanks to Edin for his telepathy!
Diffstat (limited to 'ext/standard')
-rw-r--r-- | ext/standard/math.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/ext/standard/math.c b/ext/standard/math.c index e6bf03c2c2..62bf1a4b93 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -1014,7 +1014,11 @@ PHPAPI char *_php_math_number_format(double d, int dec, char dec_point, char tho integral += integral / 3; } - reslen = integral + 1 + dec; + reslen = integral; + + if (dec) { + reslen += 1 + dec; + } /* add a byte for minus sign */ if (is_negative) { @@ -1034,21 +1038,24 @@ PHPAPI char *_php_math_number_format(double d, int dec, char dec_point, char tho int topad = declen > 0 ? dec - declen : 0; /* pad with '0's */ + while (topad--) { *t-- = '0'; } - - /* now copy the chars after the point */ - memcpy(t - declen + 1, dp + 1, declen); - t -= declen; - s -= declen; + if (dp) { + /* now copy the chars after the point */ + memcpy(t - declen + 1, dp + 1, declen); + + t -= declen; + s -= declen; + } /* add decimal point */ *t-- = dec_point; s--; } - + /* copy the numbers before the decimal place, adding thousand * separator every three digits */ while(s >= tmpbuf) { @@ -1064,7 +1071,7 @@ PHPAPI char *_php_math_number_format(double d, int dec, char dec_point, char tho } efree(tmpbuf); - + return resbuf; } |