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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
48 + 21 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2020 The PHP Group
All rights reserved.
Last updated: Mon Mar 30 10:01:26 2020 UTC