From bbf5e08fa3bbeb21f77b93f534ab31e7e68e288d Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Fri, 30 Apr 2004 13:26:06 +0000 Subject: [PATCH] MFH: Fixed bug #28228 (number_format() does not allow empty decimal separator). --- NEWS | 2 ++ ext/standard/math.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 6b63056f86..c63caa8598 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ PHP 4 NEWS then 1 character long. (Ilia) - Fixed handling of return values from storred procedures in mssql_execute() with multiple result sets returned. (Frank) +- Fixed bug #28228 (number_format() does not allow empty decimal separator). + (Ilia) - Fixed bug #28196 (missing error constants in cURL extension). (Ilia) - Fixed bug #28187 (parse_url() not handling embedded IPv6 in URLs). (Sara) - Fixed bug #28147 (Crash with drawing anti-aliased lines). (Derick) diff --git a/ext/standard/math.c b/ext/standard/math.c index ac352169f1..76797a8e7b 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -1020,7 +1020,12 @@ PHPAPI char *_php_math_number_format(double d, int dec, char dec_point, char tho is_negative = 1; d = -d; } - dec = MAX(0, dec); + if (!dec_point && dec > 0) { + d *= pow(10, dec); + dec = 0; + } else { + dec = MAX(0, dec); + } PHP_ROUND_WITH_FUZZ(d, dec); @@ -1140,6 +1145,8 @@ PHP_FUNCTION(number_format) convert_to_string_ex(t_s); if (Z_STRLEN_PP(d_p)==1) { dec_point=Z_STRVAL_PP(d_p)[0]; + } else if (Z_STRLEN_PP(d_p)==0) { + dec_point=0; } if (Z_STRLEN_PP(t_s)==1) { thousand_sep=Z_STRVAL_PP(t_s)[0]; -- 2.40.0