php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15756 bad Subtraction
Submitted: 2002-02-27 04:47 UTC Modified: 2002-02-27 05:00 UTC
From: jjulio at post dot sk Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.0.6 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jjulio at post dot sk
New email:
PHP Version: OS:

 

 [2002-02-27 04:47 UTC] jjulio at post dot sk
When i use this code:
<?
  echo 120-119.1."\n";
  echo 120-119.2."\n";
  echo 120-119.3."\n";
  echo 120-119.4."\n";
  echo 120-119.5."\n";
  echo 120-119.6."\n";
  echo 120-119.7."\n";
  echo 120-119.8."\n";
  echo 120-119.9."\n";
?>
or with variables...results was:

0.90000000000001
0.8
0.7
0.59999999999999
0.5
0.40000000000001
0.3
0.2
0.099999999999994

Is it correct or no?

How can i get correct results without using round()???


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-27 04:52 UTC] rasmus@php.net
Please don't ask support questions in the bug database.
Computers can only approximate floating point numbers to a certain level of precision.  Simply set the precision you want.  Try adding this line before your echo lines:
ini_set('precision',4);
 [2002-02-27 05:00 UTC] jjulio at post dot sk
ok, sorry
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 16 15:01:32 2024 UTC