|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-09-20 17:53 UTC] info at tellmatic dot org
Description:
------------
wrong output, not as give, drifts a lot!
Test script:
---------------
number_format("1234.560000", 50, '.', '');
Expected result:
----------------
expected output should be 1234.56 with additional 48 zeros! and not a 'random value'.
Actual result:
--------------
== 1234.55999999999994543031789362430572509765625000000000
????
can't be!
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 19:00:01 2025 UTC |
Yes, that is all number_format does. But, you asked it for 50 digits of precision for 1234.560000 which just isn't possible for computers to represent given the way they they handle floating point numbers. It has nothing to do with number_format. You will see the same if you do: ini_set('precision',50); echo 1234.560000; If you need super-precise floating point, you can't use the computers built-in floating point support. You will need to use http://php.net/gmp instead. The big drawback is that it is much much slower than the computer's native floating point support.