php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1582 Truncation error
Submitted: 1999-06-22 08:13 UTC Modified: 1999-06-22 08:24 UTC
From: louis at sitebysite dot nl Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.9 OS: Linux 2.2.10
Private report: No CVE-ID: None
 [1999-06-22 08:13 UTC] louis at sitebysite dot nl
<?
   $x=9.95;
   $x=(int)(100*$x);
   print $x;
?>

This prints 994 on our system, every time.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-06-22 08:24 UTC] sas at cvs dot php dot net
This is correct in the sense that it must be expected. Casting a floating point number to an int cuts off all decimal places (digits).

So, if $x is 9.949999 * 100 = 994.999999, casting to an integer will result in 994.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 20:00:02 2026 UTC