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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC