ID:               47418
 Updated by:       paj...@php.net
 Reported By:      cu19 at gmx dot de
-Status:           No Feedback
+Status:           Feedback
 Bug Type:         *Math Functions
 Operating System: WinXP SP3
 PHP Version:      5.3CVS-2009-02-17 (CVS)
 New Comment:

For the garbage problem, that's something else. 

Can you provide a reproduce script (with data) please?


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

[2010-02-12 11:31:41] tdietsche at comcast dot net

this sure IS a bug, scott_mac you need to wake up, if this is the best
that php handles floating point then it is worthless. In reading a value
of "19" from an excel spreadsheet via odbc, it formats it as "18.:0"
which is pure garbage and a bug to me. How can you defend that?
I can send my code if you want.

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

[2009-02-25 01:00:01] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

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

[2009-02-17 11:20:31] scott...@php.net

sc...@skinny [~] $ php -r 'var_dump(number_format(3.9, 2));'
string(4) "3.90"

Can't reproduce this on Linux.

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

[2009-02-17 10:35:08] cu19 at gmx dot de

I don't think it's a problem with limited precision but rather about
the function itself. I think a float should be able to represent 3
digits without a problem. The hex representation of the float that is to
be formatted is 0x40799998, which equals to about 3.8999996.

I think number_format should be able to round this to '3.90' instead of
displaying it as '3.8:'

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

[2009-02-17 10:18:32] scott...@php.net

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.

It's the way floating point numbers work in computers, the canned
response gives you a link to read about this some more.

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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/47418

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

Reply via email to