]> granicus.if.org Git - php/commitdiff
Fixed bug #28228 (number_format() does not allow empty decimal separator).
authorIlia Alshanetsky <iliaa@php.net>
Fri, 30 Apr 2004 13:26:01 +0000 (13:26 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Fri, 30 Apr 2004 13:26:01 +0000 (13:26 +0000)
ext/standard/math.c
ext/standard/tests/math/bug28228.phpt [new file with mode: 0755]

index b8c713d42081455b43b06a96a619b82ab96f857a..7163bfa9c563d37378e6c982bee428d250ee11b2 100644 (file)
@@ -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 (executable)
index 0000000..3d6cebc
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Bug #28228 (number_format() does not allow empty decimal separator)
+--FILE--
+<?php
+echo number_format(1234.5678, 4, '', '') . "\n";
+echo number_format(1234.5678, 4, NULL, ',') . "\n";
+echo number_format(1234.5678, 4, 0, ',') . "\n";
+echo number_format(1234.5678, 4);
+?>
+--EXPECT--
+12345678
+12,345,678
+1,23405678
+1,234.5678