Bug #75949 [Opn->Nab]: Variables have "hidden" values (tested 5.6, 7.0, 7.1)

From: Date: Sun, 11 Feb 2018 08:25:18 +0000
Subject: Bug #75949 [Opn->Nab]: Variables have "hidden" values (tested 5.6, 7.0, 7.1)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213911@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75949&edit=1

 ID:                 75949
 Updated by:         requinix@php.net
 Reported by:        me at superkot dot online
 Summary:            Variables have "hidden" values (tested 5.6, 7.0,
                     7.1)
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Math related
 Operating System:   Ubuntu, CentOS
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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.




Previous Comments:
------------------------------------------------------------------------
[2018-02-11 08:24:16] 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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=75949&edit=1


Thread (2 messages)

« previous php.bugs (#213911) next »