|  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
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:
        $test = (642 + 0.56) * 100;
        echo $test . "\n";
        $test = intval ($test);
        echo $test;

Expected result:

Actual result:

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-10 05:32 UTC]
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 Jun 20 10:01:31 2024 UTC