]> granicus.if.org Git - php/commitdiff
MFB: Fixed bug #39873 (number_format() breaks with locale & decimal points).
authorIlia Alshanetsky <iliaa@php.net>
Fri, 22 Dec 2006 04:03:35 +0000 (04:03 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Fri, 22 Dec 2006 04:03:35 +0000 (04:03 +0000)
ext/standard/math.c
ext/standard/tests/strings/bug39873.phpt [new file with mode: 0644]

index f1a6809b48444f11ee26539863283770b4d3dbcb..16b93dac54bc8bd19fd2114557d4d6e2803ee7fe 100644 (file)
@@ -929,7 +929,11 @@ PHPAPI char *_php_math_number_format(double d, int dec, char dec_point, char tho
        }
 
        /* find decimal point, if expected */
-       dp = dec ? strchr(tmpbuf, '.') : NULL;
+       if (dec) {
+               dp = strpbrk(tmpbuf, ".,");
+       } else {
+               dp = NULL;
+       }
 
        /* calculate the length of the return buffer */
        if (dp) {
diff --git a/ext/standard/tests/strings/bug39873.phpt b/ext/standard/tests/strings/bug39873.phpt
new file mode 100644 (file)
index 0000000..e73f3c8
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Bug #39873 (number_format() breaks with locale & decimal points)
+--SKIPIF--
+<?php
+if (!setlocale(LC_ALL, "ita","it","Italian","it_IT","it_IT.ISO8859-1","it_IT.ISO_8859-1")) {
+        die("skip locale needed for this test is not supported on this platform");
+}
+?>
+--FILE--
+<?php
+       setlocale(LC_ALL, "ita","it","Italian","it_IT","it_IT.ISO8859-1","it_IT.ISO_8859-1");
+       $num = 0+"1234.56";  
+       echo number_format($num,2);
+       echo "\n";
+?>
+--EXPECT--
+1,234.56