Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Detailed explanation of parseInt string conversion number in Js
Detailed explanation of parseInt string conversion number in Js
The usage of parseInt function in JavaScript is as follows:

Function parses a string and returns an integer.

ParseInt (string, radix)

String:

It is necessary. The string to parse.

Cardinal number:

Optional. Represents the radix of the number to be analyzed. The value is between 2 and 36.

If this parameter is omitted or its value is 0, the number will be parsed according to 10.

If it starts with "0X" or "0x", it is based on 16.

If the parameter is less than 2 or greater than 36, parseInt () will return NaN.

Return Value: Returns the parsed number.

Description:

When the parameter. Cardinality? When the value of is 0 or no parameter is set, parseInt () will be based on? String? Determine the radix of a number.

For example:

What if? String? Starting with "0x", parseInt () will put? String? The rest of is parsed as a hexadecimal integer.

What if? String? Starting from 0, ECMAScript v3 allows the implementation of parseInt () to parse the following characters into octal or hexadecimal numbers.

What if? String? Starting with the number 1 ~ 9, parseInt () will parse it into a decimal integer.

Tip:

Only the first number in a string is returned.

Allow spaces at the beginning and end.

If the first character of a string cannot be converted to a number, parseFloat () will return NaN.