JavaScript parseInt() Function | js intval
ExampleParsedifferentvalues:parseInt("10");parseInt("10.00");parseInt("10.33");parseInt("344566");parseInt("60");parseInt("40years");parseInt("Hewas40");TryitYourself»[1]DescriptionTheparseIntmethodparsesavalueasastringandreturnsthefirstinteger.Aradixparameterspecifiesthenumbersystemtouse:2=binary,8=octal,10=decimal,16=hexadecimal.Ifradixisomitted,JavaScriptassumesradix10.Ifthevaluebeginswith"0x",JavaScriptassumesradix16.NotesIfthefirstcharactercannotbeconverted,NaNisreturned.Leadingandtrail...
ExampleParse different values:
parseInt("10");parseInt("10.00");parseInt("10.33");parseInt("34 45 66");parseInt(" 60 ");parseInt("40 years");parseInt("He was 40");
Try it Yourself »[1] DescriptionThe parseInt method parses a value as a string and returns the first integer.
A radix parameter specifies the number system to use:
2 = binary, 8 = octal, 10 = decimal, 16 = hexadecimal.
If radix is omitted, JavaScript assumes radix 10. If the value begins with "0x", JavaScript assumes radix 16.
NotesIf the first character cannot be converted, NaN is returned.
Leading and trailing spaces are ignored.
Only the first integer found is returned.
Older browsers will return 8 for parseInt("010"). Older versions of ECMAScript used octal (radix 8) for values beginning with "0". From ECMAScript 5 (2009) default is decimal (radix 10).
Syntax Parameters Parameter Description value Required.The value t...