php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64534 Bad transfer variable from double to integer with specific number
Submitted: 2013-03-27 15:16 UTC Modified: 2013-03-27 15:51 UTC
From: izolex4 at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3Git-2013-03-27 (Git) OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: izolex4 at gmail dot com
New email:
PHP Version: OS:

 

 [2013-03-27 15:16 UTC] izolex4 at gmail dot com
Description:
------------
I have variable with type "double" with value 16.90 or 17.90 or 18.90 or 19.90. 
Now multiply variable x 100 and now set type of variable to "integer" with 
function "settype" and print this variable. Result will for example: 1989, even 
that correct result is 1990. This make only, when original value is 16.90 or 17.90 
or 18.90 or 19.90. If is original value another (for example 10.90 or 19.80), 
result will 
be correct (for example 1090 or 1980), but now is result incorrect for example 
1989.

Test script:
---------------
<?php
$double = 19.90; // Only 16.90 or 17.90 or 18.90 or 19.90 will print bad result
$integer = $double*100; // Now is value 1990
settype($integer, 'integer'); // This change value to 1989 - bug
echo $integer;

Expected result:
----------------
Value of "integer" - 1990

Actual result:
--------------
Value of "integer" - 1989

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-27 15:51 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 [2013-03-27 15:51 UTC] johannes@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.

If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/

Thank you for your interest in PHP.

.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Dec 19 14:00:02 2025 UTC