#40802 [Opn->Bgs]: number_format does not fill rounded number with zeros

From: Date: Wed, 14 Mar 2007 10:09:47 +0000
Subject: #40802 [Opn->Bgs]: number_format does not fill rounded number with zeros
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-110330@lists.php.net to get a copy of this message
 ID:               40802
 Updated by:       tony2001@php.net
 Reported By:      taco at procurios dot nl
-Status:           Open
+Status:           Bogus
 Bug Type:         *Math Functions
 Operating System: Linux 2.6.17-11-386
 PHP Version:      5.2.1
 New Comment:

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.




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

[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


Thread (4 messages)

« previous php.bugs (#110330) next »