Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23520] Android: parseInt() works in octal instead of decimal

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionInvalid
Resolution Date2016-06-17T02:57:09.000+0000
Affected Version/sRelease 5.3.0
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, parseInt
ReporterCREATIVE KAIZEN
AssigneeAshraf Abu
Created2016-06-08T13:11:26.000+0000
Updated2017-03-24T18:01:01.000+0000

Description

Comments

  1. Nazmus Salahin 2016-06-09

    Hello, I am able to reproduce this issue with given code and given step. *Steps:* 1. Create a default classic project with folloing code.
       var win= Titanium.UI.createWindow({  
           title:'Tab 1',
           backgroundColor:'#fff'
       });
       
       win.open();
       
       for(var i = 0; i < 10; ++i)
       { 
       	var text = '0' + i; 
       	Ti.API.info(parseInt(text)); 
       } 
       
    2. Build and run the app on android device. Following log is produced:
       [INFO] :   0
       [INFO] :   1
       [INFO] :   2
       [INFO] :   3
       [INFO] :   4
       [INFO] :   5
       [INFO] :   6
       [INFO] :   7
       [INFO] :   0
       [INFO] :   0
       
    Thanks *Environment*: *Device info:* HTC One (android 4.4.3) *Node.js Version:* 0.12.7 *npm Version:* 2.11.3 *Titanium SDKs:* 5.3.0.GA *Java Development Kit Version:* 1.8.0_73 *Titanium CLI Version:* 5.0.5 *Appcelerator CLI Version:* 5.2.2 *Appcelerator Studio:* 4.5.0
  2. Ashraf Abu 2016-06-17

    [~CREATIVE KAIZEN] This is a native javascript behaviour. Here's a related link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt {quote}radix: Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior. Different implementations produce different results when a radix is not specified, usually defaulting the value to 10.{quote} The best solution for this for now is thus
     parseInt(text,10) 
    . Which is to specify the radix as base 10 aka decimal. This behavior will be updated to match the default expectation of decimal in the near future.
  3. Ashraf Abu 2016-06-17

    I'm going to resolve this ticket.
  4. Lee Morris 2017-03-24

    Closing ticket as invalid with reference to the above comments.

JSON Source