php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64668 Casting from string containing exponential notation number to int
Submitted: 2013-04-18 17:34 UTC Modified: 2013-04-18 17:43 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: biowep at gmail dot com Assigned:
Status: Not a bug Package: *Programming Data Structures
PHP Version: 5.4.14 OS: Windows 7 x64 SP1
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: biowep at gmail dot com
New email:
PHP Version: OS:

 

 [2013-04-18 17:34 UTC] biowep at gmail dot com
Description:
------------
When trying to cast a numeric string value in the exponential notation to int, the 
result doesn't match with the initial value. While the casting to float from 
string works well. Also casting to int from the same value stored in a float 
variable workes well.
The function intval() has the same problem.

Test script:
---------------
<?php

echo 1E2 . "<br />";
echo (float)1E2 . "<br />";
echo (int)1E2 . "<br />";
echo intval(1E2) . "<br />";
echo (float)"1E2" . "<br />";
echo (int)"1E2" . "<br />";//problem
echo intval("1E2") . "<br />";//problem

?>

Expected result:
----------------
100
100
100
100
100
100
100

Actual result:
--------------
100
100
100
100
100
1
1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-04-18 17:43 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 [2013-04-18 17:43 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

the cast from string to int cuts the number of on the first non-digit (essentially using the system's atoi() function) this is expected behavior.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Dec 05 12:03:38 2021 UTC