php.net |  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
 [2004-01-12 01:48 UTC] yehlu at ms1 dot hinet dot net
Description:
------------
<?php
    $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
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-12 06:17 UTC] eru@php.net
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: Sun Dec 22 06:01:30 2024 UTC