|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26874 round floting number have bad result
Submitted: 2004-01-12 01:48 UTC Modified: 2005-09-22 21:39 UTC
From: yehlu at ms1 dot hinet dot net Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.3.4 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: yehlu at ms1 dot hinet dot net
New email:
PHP Version: OS:


 [2004-01-12 01:48 UTC] yehlu at ms1 dot hinet dot net
    $a = 3100;
    echo "\$a :".$a."\n";
    $a *= 1.025;
    echo "\$a * 1.025 :".$a."\n";
    echo "round \$a:".round($a)."\n";  //get 3177
    echo "round \$a:".round("$a")."\n"; //get 3178
    $b = "3177.5";
    echo "\$b:".$b."\n";
    echo "round \$b:".round($b)."\n"; //get 3178


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-12 06:17 UTC]
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.
Thank you for your interest in PHP.


PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 19 05:01:30 2024 UTC