Is This What parseInt Means?

Discussion in 'JavaScript' started by gobbly2100, Dec 11, 2007.

  1. #1
    Hello,

    I just wondered if parseInt is short for "Parse Integer" because after all, that is what it is doing?
     
    gobbly2100, Dec 11, 2007 IP
  2. hrcerqueira

    hrcerqueira Peon

    Messages:
    125
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    yes it is. you also have a parseFloat function for example.
     
    hrcerqueira, Dec 12, 2007 IP
  3. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    var num = new String('55');
    alert(parseInt(num));
    
    PHP:
     
    MMJ, Dec 12, 2007 IP
  4. rock-The God

    rock-The God Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The parseInt() function parses a string and returns an integer.

    The radix parameter is used to specify which numeral system to be used, for example, a radix of 16 (hexadecimal) indicates that the number in the string should be parsed from a hexadecimal number to a decimal number.

    If the radix parameter is omitted, JavaScript assumes the following:

    * If the string begins with "0x", the radix is 16 (hexadecimal)
    * If the string begins with "0", the radix is 8 (octal). This feature is deprecated
    * If the string begins with any other value, the radix is 10 (decimal)

    Syntax
    parseInt(string, radix)

    while
    parseFloat() function parses a string and returns a floating point number.

    This function determines if the first character in the specified string is a number. If it is, it parses the string until it reaches the end of the number, and returns the number as a number, not as a string.
     
    rock-The God, Dec 12, 2007 IP
  5. temp2

    temp2 Well-Known Member

    Messages:
    1,231
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    150
    Digital Goods:
    2
    #5
    The parseInt method returns an integer value equal to the number contained in numstring. If no prefix of numstring can be successfully parsed into an integer, NaN (not a number) is returned.
    parseInt("abc") // Returns NaN.
    parseInt("12abc") // Returns 12.
     
    temp2, Dec 13, 2007 IP