Javascript Knowledge

  • what is javascript

  • javascript Variable
  • javascript function
  • javascript Event

  • JavaScript If
  • javascript for

  • javascript object
  • Javascript String
  • Javascript Date
  • Javacsript Array
  • Javascript Math

  • Javascript onclick
  • JavaScript onload

  • Javascript Frame
  • Javascript Image
  • Javascript Style
  • Javascript Textarea
  • Javascript Table
  • Javascript window
  • Javascript Location
  • Javacsript form
  • Javascript Checkbox
  • Javascript Input
  • Javascript Radio
  • Javascript Select
  • Javascript Submit

  • Javascript alert
  • Javascript close
  • Javascript confirm
  • Javascript Document open
  • Javascript getElementById
  • Javascript print
  • Javascript reload
  • Javascript remove
  • JavaScript replace
  • Javascript setTimeout
  • JavaScript split
  • JavaScript substring
  • Javascript window open
  • window showmodaldialog

  • Javascript href
  • Javascript IFrame
  • Javascript innerHTML
  • Javascript selectedindex
  • Javascript URL
  • Javascript window Location

  • javascript write to file
  • JavaScript write
  • javascript string to integer
  • Javascript popup
  • Javascript return
  • Javascript Obfuscator
  • Javascript disable
  • Javascript Hide
  • More others

    Javascript
    CSS
    PHP

     

    Javascript string to integer


    javascript string to integer
    JavaScript parseInt() Function
    Definition and Usage

    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)

    Parameter

    Description

    string

    Required. The string to be parsed

    radix

    Optional. A number (from 2 to 36) that represents the numeral system to be used

    Javascript string to integer examples:
    Examples (comments in each line give the conversion results):

    parseFloat('1.45kg') // 1.45
    parseFloat('77.3') // 77.3
    parseFloat('077.3') // 77.3
    parseFloat('0x77.3') // 0
    parseFloat('.3') // 0.3
    parseFloat('0.1e6') // 100000
    parseInt('123.45') // 123
    parseInt('77') // 77
    parseInt('077',10) // 77
    parseInt('77',8) // 63 (= 7 + 7*8)
    parseInt('077') // 63 (= 7 + 7*8)
    parseInt('77',16) // 119 (= 7 + 7*16)
    parseInt('0x77') // 119 (= 7 + 7*16)
    parseInt('099') // 0 (9 is not an octal digit)
    parseInt('99',8) // 0 or NaN, depending on the platform
    parseInt('0.1e6') // 0
    parseInt('ZZ',36) // 1295 (= 35 + 35*36)

    Tips and Notes

    Note: Only the first number in the string is returned!

    Note: Leading and trailing spaces are allowed.

    Note: If the first character cannot be converted to a number, parseInt() returns NaN.

     





















     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

  • Javascript |