php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21459 converting float to int failed sometime
Submitted: 2003-01-06 05:17 UTC Modified: 2003-01-06 06:18 UTC
From: bibifoc23 at yahoo dot fr Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.0 OS: linux and windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bibifoc23 at yahoo dot fr
New email:
PHP Version: OS:

 

 [2003-01-06 05:17 UTC] bibifoc23 at yahoo dot fr
<?php

$nb = (15.2 - 15) * 100;
echo $nb."\n";
echo (int)$nb; 

?>

The output should be 20 and 20, but it's  20 and 19 !!!!

this strange behavior does not appear for all value.

I test on Redhat 6.2 and windows 2000 SP3

I think there was a link to another bug n?21458

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-06 06:18 UTC] georg@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the existing bug instead.

Thank you for your interest in PHP.


 [2010-08-19 20:37 UTC] simpson at wp dot pl
$val = 32.48;
var_dump($val); // float(32.48);
$val = $val * 100;
var_dump($val); // float(3248);
var_dump((int)$val); // int(3247)
var_dump((int)(string)$val); // int(3248)

Why not to add double conversion at the source code level instead of .php level?
So the (int) would do (int)(string)$val

I tested this with milions of options and allways worked as i expected.

Cheers.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 26 20:00:02 2025 UTC