Skip to content

Instantly share code, notes, and snippets.

@joschuck
Last active March 26, 2016 16:19
Show Gist options
  • Select an option

  • Save joschuck/2f1087b6fbc846b19677 to your computer and use it in GitHub Desktop.

Select an option

Save joschuck/2f1087b6fbc846b19677 to your computer and use it in GitHub Desktop.
Parse Numbers Javascript
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) // NaN (0 in very old browsers e.g. IE3)
parseInt('0.1e6') // 0
parseInt('ZZ',36) // 1295 (= 35 + 35*36)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment