php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75949 Variables have "hidden" values (tested 5.6, 7.0, 7.1)
Submitted: 2018-02-11 08:24 UTC Modified: 2018-02-11 08:25 UTC
From: me at superkot dot online Assigned:
Status: Not a bug Package: Math related
PHP Version: Irrelevant OS: Ubuntu, CentOS
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: me at superkot dot online
New email:
PHP Version: OS:

 

 [2018-02-11 08:24 UTC] me at superkot dot online
Description:
------------
Calculation results in number different from what can be seen (and what should be). 
Happens with 2263.20 or 2263.70 in the presented script example.


Test script:
---------------
<?php

$order_total = '2263.20';
$order_total_nocents = $order_total * 100;
echo $order_total . ' '. (int) $order_total . ' ' . $order_total_nocents . ' '. (int) $order_total_nocents;

if ( $order_total_nocents != "226320" && $order_total_nocents != 226320 ) {
    echo '<br />Error! '. $order_total_nocents;
}

Expected result:
----------------
2263.20 2263 226320 226320

Actual result:
--------------
2263.20 2263 226320 226319
Error! 226320

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-11 08:25 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-02-11 08:25 UTC] requinix@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.

If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC