From: Ilia Alshanetsky Date: Fri, 30 Apr 2004 13:26:01 +0000 (+0000) Subject: Fixed bug #28228 (number_format() does not allow empty decimal separator). X-Git-Tag: RELEASE_0_1~318 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=91e9545f4ff5b92bc8c8699c8111bfa663b544a5;p=php Fixed bug #28228 (number_format() does not allow empty decimal separator). --- diff --git a/ext/standard/math.c b/ext/standard/math.c index b8c713d420..7163bfa9c5 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]; diff --git a/ext/standard/tests/math/bug28228.phpt b/ext/standard/tests/math/bug28228.phpt new file mode 100755 index 0000000000..3d6cebcfd4 --- /dev/null +++ b/ext/standard/tests/math/bug28228.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #28228 (number_format() does not allow empty decimal separator) +--FILE-- + +--EXPECT-- +12345678 +12,345,678 +1,23405678 +1,234.5678