php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80840 convert to int
Submitted: 2021-03-06 05:00 UTC Modified: 2021-03-06 07:21 UTC
From: reza dot cyber at gmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 7.3.27 OS: all
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: reza dot cyber at gmail dot com
New email:
PHP Version: OS:

 

 [2021-03-06 05:00 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-06 07:21 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2021-03-06 07:21 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.

> but when I use the round function it returns the correct answer.
Using round() is the solution.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon May 10 23:01:24 2021 UTC