ID:               40802
 User updated by:  taco at procurios dot nl
 Reported By:      taco at procurios dot nl
 Status:           Bogus
 Bug Type:         *Math Functions
 Operating System: Linux 2.6.17-11-386
 PHP Version:      5.2.1
 New Comment:

I agree that this is normal behaviour for floats, but the same bug
appears when you would pass a string. Does number_format cast strings
to floats internally?


Previous Comments:
------------------------------------------------------------------------

[2007-03-14 10:09:47] [EMAIL PROTECTED]

Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.

If you would like to know more about "floats" and what IEEE
754 is read this:
http://docs.sun.com/source/806-3568/ncg_goldberg.html
 
Thank you for your interest in PHP.



------------------------------------------------------------------------

[2007-03-14 10:07:19] taco at procurios dot nl

Description:
------------
Since there is no way to tell number_format to use a specified decimal
separator and thousands separator without rounding the number I wanted
to set the amount of decimals bigger than the given amount of decimals
to strip the trailing zeros afterwards.

However, the string number_format returned did not only add zeros to
the given number:

$ php -v
PHP 5.2.1-0.dotdeb.1 with Suhosin-Patch 0.9.6.2 (cli) (built: Feb  9
2007 04:46:32) 
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
$ php -r "echo number_format(2.333333, 60, ',', '.');"
2,333333000000000101437080957111902534961700439453125000000000

Reproduce code:
---------------
echo number_format(2.333333, 60, ',', '.');

Expected result:
----------------
2,333333000000000000000000000000000000000000000000000000000000

Actual result:
--------------
2,333333000000000101437080957111902534961700439453125000000000


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=40802&edit=1

Reply via email to