php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54184 (int)(1.13*100) returns 112 !!!!! (should be 113)
Submitted: 2011-03-07 16:56 UTC Modified: 2011-03-07 17:23 UTC
From: yuriy at vihv dot org Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.3.5 OS: Linux 2.6.33.3-85.fc13
Private report: No CVE-ID: None
 [2011-03-07 16:56 UTC] yuriy at vihv dot org
Description:
------------
Sample code below returns 112 instead of 113. echo (int)(113); and echo 1.13*100; 
works just fine.

Other numbers like 2.13, 1.14 works fine

Well, in fact i use php 5.3.3. No i wont upgrade. I've post some bug a few years 
ago and still get no response. So i post it here just in case. Go ahead, mark it 
as "could not reproduce" and go get one more cup of coffee... Or you can really 
check it, bug looks a bit ugly.

Test script:
---------------
<?php

echo (int)(1.13*100);

?>

Expected result:
----------------
113

Actual result:
--------------
112

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-07 17:23 UTC] derick@php.net
-Status: Open +Status: Bogus
 [2011-03-07 17:23 UTC] derick@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.

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 13:01:30 2024 UTC