Convert Number to String

Discussion in 'JavaScript' started by asuni449, Feb 24, 2009.

  1. #1
    Hi all,
    How to convert Number to String in Javascript.
    Thanks.
    :confused:
     
    asuni449, Feb 24, 2009 IP
  2. astupidname

    astupidname Peon

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <script type="text/javascript">

    var num = 3;
    alert(typeof num);
    num = 3 + ''; //simplest to just add a blank string on to the number
    alert(typeof num);

    </script>
     
    astupidname, Feb 25, 2009 IP
  3. mytor

    mytor Peon

    Messages:
    80
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    string = number.toString();
    
    Code (markup):
     
    mytor, Feb 25, 2009 IP
  4. igor398

    igor398 Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Why do you want to convert?
    js engine does it automatically
     
    igor398, Mar 22, 2009 IP
  5. robertstr

    robertstr Member

    Messages:
    218
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #5
    Hi!

    For converting numbers to binary, octal, or hexadecimal strings (or to any other base) you can use, in JavaScript 1.1, the standard method Number.toString(radix) for converting a number to a string representing that number in a non-decimal number system (e.g. to a string of binary, octal or hexadecimal digits)
    Wish you succees.
     
    robertstr, Mar 25, 2009 IP