php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69039 (int)
Submitted: 2015-02-12 09:26 UTC Modified: 2015-02-12 11:39 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: marc at webetsolutions dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS: Linux
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: marc at webetsolutions dot com
New email:
PHP Version: OS:

 

 [2015-02-12 09:26 UTC] marc at webetsolutions dot com
Description:
------------
Just a litle question

if i calculate 

echo 264.40 * 100;
The result is : 26440

if i calculate 
echo (int)(264.40 * 100);
The result is 26439

The problem seem to be for 255 to 327

Why ?


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-02-12 11:39 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2015-02-12 11:39 UTC] nikic@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.


 [2015-02-12 11:41 UTC] nikic@php.net
(int) casts are truncating (which means "round down" in this case). Due to limited floating point precision 264.40 * 100 is in reality something like 26439.999999999, which is then rounded down to 26439. You may try setting the "precision" ini setting to a higher value in order to see this.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC