Bug #77139 [Opn->Nab]: intval gives wrong results

From: Date: Sun, 11 Nov 2018 18:16:26 +0000
Subject: Bug #77139 [Opn->Nab]: intval gives wrong results
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217906@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77139&edit=1 ID: 77139 Updated by: cmb@php.net Reported by: markus at senoner dot com Summary: intval gives wrong results -Status: Open +Status: Not a bug Type: Bug Package: *Math Functions Operating System: Linux (any) PHP Version: Irrelevant -Assigned To: +Assigned To: cmb 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-11-11 18:14:04] spam2 at rhsoft dot net http://php.net/manual/de/language.types.float.php ------------------------------------------------------------------------ [2018-11-11 18:06:02] markus at senoner dot com Description: ------------ Please try: echo intval(8.2*1000); echo intval(8.2*100); echo intval(8.2*10); echo intval(8.2*1); result: 8200 819 <--- this is wrong! 82 8 happens in PHP 7.2 as well as in PHP 5.X If 819 is the result of an internal representation of 8.2 as 8.199999..., than why does the first operation in this example not give 8199 ?!? Expected result: ---------------- 8.2*100 should give 820, not 819 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77139&edit=1

« previous php.bugs (#217906) next »