How to change integer to string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Krupa Kiran
    New Member
    • Apr 2007
    • 2

    How to change integer to string

    Hi i have function in script. I did a small calculation in that function when i try to pass a value to in Field thet only passes integer value. But i need to pass both String and the integer value. So is it possible to convert from integer to string. Please let me know.

    Thanks and Regards,
    Kiran Nandamudi
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Krupa Kiran
    Hi i have function in script. I did a small calculation in that function when i try to pass a value to in Field thet only passes integer value. But i need to pass both String and the integer value. So is it possible to convert from integer to string. Please let me know.

    Thanks and Regards,
    Kiran Nandamudi
    Javascript's type checking system is such that you can pass an integer to a function that "expects" a string.

    Comment

    • kaleeswaran
      New Member
      • Mar 2007
      • 132

      #3
      Originally posted by Krupa Kiran
      Hi i have function in script. I did a small calculation in that function when i try to pass a value to in Field thet only passes integer value. But i need to pass both String and the integer value. So is it possible to convert from integer to string. Please let me know.

      Thanks and Regards,
      Kiran Nandamudi
      you can use:
      String to Integer convertion
      parseFloat(var)

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        hi ...

        you did get the answer in post #2 already, but let me explain that in more detail a little bit. JavaScript uses implicit type-casting dependent on what the OPERATION expects. so when you have a number-type and the operation expects a string javascript will cast the number to a string. in case you want to do it explicitly before then you may use:

        [CODE=javascript]var n = 1;
        var s = n.toString();

        // now var s has a string '1' assigned :)
        [/CODE]
        note: sometimes the implict typecasting is a little bit tricky ... have a look at this:

        [CODE=javascript]// we compare an empty string to a number 0
        var val = '' == 0;

        // val is now true since we compare different types and js
        // implcitly casts the types
        // so val will be true in the next examples too:
        val = ' ' == 0;
        val = '0' == 0;
        val = '0000000' == 0;

        // in case you need to check the types too and avoid
        // the casting here you could use the identity-operator ===
        val = '0' === '';

        // now val is false since the types are different
        [/CODE]
        kind regards

        Comment

        Working...