php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67746 Bugs in built-in functions
Submitted: 2014-08-02 11:38 UTC Modified: 2014-08-05 19:14 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jaffar dot abdulla dot aljamry at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.5.15 OS: Linux
Private report: No CVE-ID: None
 [2014-08-02 11:38 UTC] jaffar dot abdulla dot aljamry at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.number-format
From manual page: http://php.net/function.ceil
From manual page: http://php.net/function.floor
---

inappropriate result while using function "number_format", it's changing the value, it should only format number and keep the value same.

Test script:
---------------
Simple code:

$text = "685484585478488466";
echo $text = intval($text);
echo "\n";
$text = number_format($text, 0, ".", "");
echo $text;

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

Output:
685484585478488466
685484585478488448




Expected result:
----------------
Output:
685484585478488466
685484585478488466

Actual result:
--------------
Output:
685484585478488466
685484585478488448

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-02 12:37 UTC] jaffar dot abdulla dot aljamry at gmail dot com
-Type: Documentation Problem +Type: Bug
 [2014-08-02 12:37 UTC] jaffar dot abdulla dot aljamry at gmail dot com
I have changed Bug Type to "Bug".
 [2014-08-05 19:14 UTC] aharvey@php.net
-Status: Open +Status: Not a bug -Package: Performance problem +Package: Scripting Engine problem
 [2014-08-05 19:14 UTC] aharvey@php.net
number_format() casts the input value to a float before formatting (indicated by the "float $number" in the function prototype at http://php.net/number_format), which results in a loss of precision and the output you're seeing. Here's a clearer example just showing the casting behaviour: http://3v4l.org/MNkGq

You may also be interested in http://www.floating-point-gui.de/.

Closing not a bug, as this is expected behaviour.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 04:00:01 2026 UTC