php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27199 intval changes value on one particular number
Submitted: 2004-02-10 00:33 UTC Modified: 2004-02-10 05:32 UTC
From: ribarra at innox dot com dot mx Assigned:
Status: Not a bug Package: *Math Functions
PHP Version: 4.3.4 OS: Linux Mandrake 9.2
Private report: No CVE-ID: None
 [2004-02-10 00:33 UTC] ribarra at innox dot com dot mx
Description:
------------
The following code should output exactly the same number in both echo cases but it doesn't. However, multiply the number by 1000 instead of the 100 on the first line and everything will work fine.

Reproduce code:
---------------
<?php
        $test = (642 + 0.56) * 100;
        echo $test . "\n";
        $test = intval ($test);
        echo $test;
?>


Expected result:
----------------
64256
64256

Actual result:
--------------
64256
64255

Very weird, I have only seen it happen with this particular case.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-10 05:32 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.
 
Thank you for your interest in PHP.

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC