php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42831 function number_format() seems to return a wrong value
Submitted: 2007-10-02 16:55 UTC Modified: 2007-11-21 03:58 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: naweokawa at free dot fr Assigned: ab5602 (profile)
Status: Not a bug Package: Strings related
PHP Version: 5.2.4 OS: Solaris 10
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: naweokawa at free dot fr
New email:
PHP Version: OS:

 

 [2007-10-02 16:55 UTC] naweokawa at free dot fr
Description:
------------
When you use the function number_format with a float value, it seems to returns a value INPUT_FLOAT*100



Reproduce code:
---------------
$num2=123456.55;

number_format($num2 , 2, ',', ' ');

// OUTPUT
output : 12 345 655,00 (should be 123 456,55 ) 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-03 08:19 UTC] tony2001@php.net
Cannot reproduce.
 [2007-10-03 09:13 UTC] naweokawa at free dot fr
it seems to run correctly on Linux 
(tested on Linux xxx 2.6.8-2-386 #1 Tue Aug 16 12:46:35 UTC 2005 i686 GNU/Linux)

Reproduce code:
---------------
$num2=123456.55;

echo number_format($num2 , 2, ',', ' ');
echo "<br />\n";
echo number_format($num2 , 3, ',', ' ');

// OUTPUT
123 456,55  (OK)
123 456,550 (OK)

However on Solaris10 (SunOS xxx 5.10 Generic_118855-33 i86pc i386 i86pc)

Reproduce code:
---------------
$num2=123456.55;

echo number_format($num2 , 2, ',', ' ');
echo "<br />\n";
echo number_format($num2 , 3, ',', ' ');

// OUTPUT
12 345 655,00 (KO)
123 456 550,000 (KO)


- The Locale settings shouldn't used for this function ?
- php-5.2.4 compiled with cc: Sun C 5.8 2005/10/13
 [2007-10-03 09:47 UTC] tony2001@php.net
Try compiling with GCC.
 [2007-10-03 10:25 UTC] naweokawa at free dot fr
Always same issue with (GCC) 3.4.3 (csl-sol210-3_4-branch+sol_rpath)
 [2007-10-03 10:56 UTC] tony2001@php.net
GCC 3.4.3 is quite old and is known to have problems on SPARC.
Try with something newer (the latest available would be great).
 [2007-10-03 21:00 UTC] naweokawa at free dot fr
This issue doesn't seems appear on Solaris 10 x86 32 bits. 
But it persits on Solaris 10 /  AMD64 compiled on full 64bits.
 [2007-10-11 00:30 UTC] ab5602@php.net
Hi, I cannot reproduce either.

$ uname -a
SunOS opteron 5.10 Generic_118855-14 i86pc i386 i86pc
$ isainfo -v
64-bit amd64 applications
        sse3 sse2 sse fxsr amd_3dnowx amd_3dnow amd_mmx mmx cmov amd_sysc cx8 
        tsc fpu 
32-bit i386 applications
        sse3 sse2 sse fxsr amd_3dnowx amd_3dnow amd_mmx mmx cmov amd_sysc cx8 
        tsc fpu 
$ ./php -v 
PHP 5.2.5-dev (cli) (built: Oct 10 2007 19:51:01) 
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
$ cat ./num.php 
<?
$num2=123456.55;
echo number_format($num2 , 2, ',', ' ');
?>
$ ./php ./num.php 
123 456,55
 [2007-10-11 14:45 UTC] naweokawa at free dot fr
So, I re-test the code again :

$ cat num.php
<?php
$num2=123456.55;
echo number_format($num2 , 2, ',', ' ') ."\n";
?>

$ /HOME/php5.2-200710111030_gcc_64/bin/php -f ./num.php
12 345 655,00

$ file /HOME/php5.2-200710111030_gcc_64/bin/php
/HOME/php5.2-200710111030_gcc_64/bin/php:       ELF 64-bit LSB executable AMD64 Version 1 [SSE2 SSE FXSR FPU], dynamically linked, not stripped

Not really same flags like you : 
$ isainfo -v
64-bit amd64 applications
        sse2 sse fxsr amd_3dnowx amd_3dnow amd_mmx mmx cmov amd_sysc cx8 tsc
        fpu
32-bit i386 applications
        sse2 sse fxsr amd_3dnowx amd_3dnow amd_mmx mmx cmov amd_sysc cx8 tsc
        fpu

$ uname -a
SunOS tdb 5.10 Generic_118855-33 i86pc i386 i86pc

$ /HOME/php5.2-200710111030_gcc_64/bin/php -v
PHP 5.2.5-dev (cli) (built: Oct 11 2007 14:51:34)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

$ ldd /HOME/php5.2-200710111030_gcc_64/bin/php
        librt.so.1 =>    /lib/64/librt.so.1
        libresolv.so.2 =>        /lib/64/libresolv.so.2
        libm.so.2 =>     /lib/64/libm.so.2
        libnsl.so.1 =>   /lib/64/libnsl.so.1
        libsocket.so.1 =>        /lib/64/libsocket.so.1
        libz.so.1 =>     /usr/lib/64/libz.so.1
        libxml2.so.2 =>  /usr/local/lib/libxml2.so.2
        libpthread.so.1 =>       /lib/64/libpthread.so.1
        libc.so.1 =>     /lib/64/libc.so.1
        libaio.so.1 =>   /lib/64/libaio.so.1
        libmd5.so.1 =>   /lib/64/libmd5.so.1
        libmp.so.2 =>    /lib/64/libmp.so.2
        libscf.so.1 =>   /lib/64/libscf.so.1
        libdoor.so.1 =>  /lib/64/libdoor.so.1
        libuutil.so.1 =>         /lib/64/libuutil.so.1

All is OK on 32bits compilation.

That's a zone solaris on Sun Fire v20z (Dual CPU AMD64  Socket940).

Greetings.
 [2007-10-13 17:12 UTC] ab5602@php.net
Hi, thanks for the update.  I do have the binary linked against the 64 libs but still no luck reproducing the problem with the current snapshot.  If I can find some time, I'll try and replicate your setup better, including your newer OS patch level.

$ ldd ./php
        librt.so.1 =>    /lib/64/librt.so.1
        libresolv.so.2 =>        /lib/64/libresolv.so.2
        libm.so.2 =>     /lib/64/libm.so.2
        libnsl.so.1 =>   /lib/64/libnsl.so.1
        libsocket.so.1 =>        /lib/64/libsocket.so.1
        libc.so.1 =>     /lib/64/libc.so.1
        libaio.so.1 =>   /lib/64/libaio.so.1
        libmd5.so.1 =>   /lib/64/libmd5.so.1
        libmp.so.2 =>    /lib/64/libmp.so.2
        libscf.so.1 =>   /lib/64/libscf.so.1
        libdoor.so.1 =>  /lib/64/libdoor.so.1
        libuutil.so.1 =>         /lib/64/libuutil.so.1
$ ./php ./num.php 
123 456,55
 [2007-11-21 03:58 UTC] ab5602@php.net
I have tried under several other 64-bit Solaris systems with similar specs, but am still unable to reproduce this.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 06:01:32 2025 UTC