Bug #80840 [Opn->Nab]: convert to int
Edit report at https://bugs.php.net/bug.php?id=80840&edit=1
ID: 80840
Updated by: requinix@php.net
Reported by: reza dot cyber at gmail dot com
Summary: convert to int
-Status: Open
+Status: Not a bug
Type: Bug
Package: Math related
Operating System: all
PHP Version: 7.3.27
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.
> but when I use the round function it returns the correct answer.
Using round() is the solution.
Previous Comments:
------------------------------------------------------------------------
[2021-03-06 05:00:34] reza dot cyber at gmail dot com
Description:
------------
Hi. I wrote these lines for the PHP 7.3.5
these codes must return 13495 but return 13494.
I try with the intval function and the result is the same as before.
but when I use the round function it returns the correct answer.
I tested by any PHP version in Linux, Windows, and other online PHP testers.
thanks
RezaAb
Test script:
---------------
$no = 134.95;
$number = (int)($no*100);
echo $number;//print 13494
Expected result:
----------------
13495
Actual result:
--------------
13494
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80840&edit=1
Thread (2 messages)