Browse Source

Fixed bug #28228 (number_format() does not allow empty decimal separator).

PHP-5.0
Ilia Alshanetsky 22 years ago
parent
commit
91e9545f4f
  1. 9
      ext/standard/math.c
  2. 14
      ext/standard/tests/math/bug28228.phpt

9
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];

14
ext/standard/tests/math/bug28228.phpt

@ -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
Loading…
Cancel
Save