Bug #78408 [Opn->Nab]: Floating point rounding error
| From: | requinix@php.net | Date: | Tue, 13 Aug 2019 08:35:10 +0000 |
| Subject: | Bug #78408 [Opn->Nab]: Floating point rounding error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-222215@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78408&edit=1
ID: 78408
Updated by: requinix@php.net
Reported by: djurredenboer at gmail dot com
Summary: Floating point rounding error
-Status: Open
+Status: Not a bug
Type: Bug
Package: Math related
Operating System: Linux and Mac
PHP Version: 7.3.8
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:
------------------------------------------------------------------------
[2019-08-13 08:32:39] djurredenboer at gmail dot com
Description:
------------
If you add up 0.30 and 0.15 it and then cast to integer it will end up in 44 instead of 45
Test script:
---------------
<?php
$test = 0.30 + 0.15;
$test2 = ((int)(100 * $test));
echo $test2;
Expected result:
----------------
45
Actual result:
--------------
44
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78408&edit=1