php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46233 Difference between to Float Type Castings
Submitted: 2008-10-05 07:38 UTC Modified: 2008-10-05 10:19 UTC
Votes:5
Avg. Score:5.0 ± 0.0
Reproduced:5 of 5 (100.0%)
Same Version:5 (100.0%)
Same OS:5 (100.0%)
From: butterfly110Pro at yahoo dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.2.6 OS: Windows 2003 Server R2
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: butterfly110Pro at yahoo dot com
New email:
PHP Version: OS:

 

 [2008-10-05 07:38 UTC] butterfly110Pro at yahoo dot com
Description:
------------
Salam,
I Saw Differences Between Float Type Castings. My Trying Are Become Below, and This May Be Extensible For Other Numbers and Should Be Researches!
Thanks.

Reproduce code:
---------------
echo (float)1199999 . '<br />';
echo (float)1200000 . '<br />';
echo (float)1200001 . '<br />';

echo (float)1300000 . '<br />';

echo (float)1399999 . '<br />';
echo (float)1400000 . '<br />';
echo (float)1400001 . '<br />';

echo '-------------------------<br />';

echo (float)11999999 . '<br />';
echo (float)12000000 . '<br />';
echo (float)12000001 . '<br />';

echo (float)13000000 . '<br />';

echo (float)13999999 . '<br />';
echo (float)14000000 . '<br />';
echo (float)14000001 . '<br />';

echo '-------------------------<br />';

echo (float)119999999 . '<br />';
echo (float)120000000 . '<br />';
echo (float)120000001 . '<br />';

echo (float)130000000 . '<br />';

echo (float)139999999 . '<br />';
echo (float)140000000 . '<br />';
echo (float)140000001 . '<br />';


Expected result:
----------------
1199999
1200000
1200001
1300000
1399999
1400000
1400001
-------------------------
11999999
12000000
12000001
13000000
13999999
14000000
14000001
-------------------------
119999999
120000000
120000001
130000000
139999999
140000000
140000001


Actual result:
--------------
1199999
1.2E+6
1200001
1300000
1399999
1.4E+6
1400001
-------------------------
11999999
1.2E+7
12000001
13000000
13999999
1.4E+7
14000001
-------------------------
119999999
1.2E+8
120000001
130000000
139999999
1.4E+8
140000001


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-05 10:19 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://docs.sun.com/source/806-3568/ncg_goldberg.html
 
Thank you for your interest in PHP.

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC