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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ribarra at innox dot com dot mx
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2020 The PHP Group
All rights reserved.
Last updated: Wed Dec 02 04:01:24 2020 UTC