php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10411 number_format returns wrong values
Submitted: 2001-04-19 17:35 UTC Modified: 2001-04-20 15:14 UTC
From: mark at artshouse dot com Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 4.0.4pl1 OS: Solaris 8, Slackware 7.0
Private report: No CVE-ID: None
 [2001-04-19 17:35 UTC] mark at artshouse dot com
number_format returns wrong values in certain situations, 
here is a code example...

$value = 504;
$calcs_a = number_format($value,2);

$othervalue = 504;
$calcs_b = number_format($othervalue,2);

$total = number_format($calcs_a + calcs_b,2);

this returns:
$calcs_a is 504.00
$calcs_b is 504.00
$total is 1.00  (should be 1008.00)

I have seen this on several occasions now on multiple 
machines/setups/Oses



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-19 17:53 UTC] joey@php.net
Try changing:
$total = number_format($calcs_a + calcs_b,2);
to
$total = number_format($calcs_a + $calcs_b,2);
(Note the missing $)

Works just fine here with that small adjustment.
 [2001-04-20 15:14 UTC] mark at artshouse dot com
That was just a typo on my part entering the information 
here.  The bug still exists, and I think it specifically 
has to do with values set as float,2 from MySQL. It doesn't 
happen every time, but I have seen this on at least 5 
occasions now (in 5 different sets of code).

I can recreate it within my code, but you don't want me to 
paste my code (its all intermingled in a 600 lines of 
script)

check it out specifically using values pulled from MySQL 
with a type of float,2.

Here's the kicker, if I do something like 
$total=number_format($totals,2); print $total; the bug 
exists...if I do print number_format($totals,2) it works 
normally.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 21:01:28 2024 UTC