1. #1
    Sencha User
    Join Date
    Mar 2012
    Location
    Bangalore, India
    Posts
    139
    Vote Rating
    1
    shaleen is on a distinguished road

      0  

    Default String to int

    hi everyone

    I am extracting values from the json files using store and model in sencha.
    some of the values extracted are int. I want to perform operation on it(mathematical)......but it is a string.

    How can i convert this string to int or is there any other way of doing mathematical operation on them.

    This is coming from json file-
    open_value=this.get('open');

    This is the operation which i want to do
    alert(open_value+12);

    Suppose value of open_value = 30
    then output should come 42 and not 3012 which is coming in present case

  2. #2
    Ext JS Premium Member
    Join Date
    Apr 2008
    Posts
    406
    Vote Rating
    69
    rich02818 is infamous around these parts rich02818 is infamous around these parts rich02818 is infamous around these parts

      0  

    Default

    Your variable open_value is being interpreted as a string, and then the + 12 is treated as string concatenation. Try this:

    alert(parseInt(open_value,10) + 12);

  3. #3
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,566
    Vote Rating
    54
    Animal will become famous soon enough Animal will become famous soon enough

      0  

    Default

    ExtJS does this for you.

    Just specify a field type when you define your Model.

  4. #4
    Sencha User
    Join Date
    Mar 2012
    Location
    Bangalore, India
    Posts
    139
    Vote Rating
    1
    shaleen is on a distinguished road

      0  

    Default

    Thanks its working fine.

Thread Participants: 2

Tags for this Thread