![]() ![]() If the input string begins with any other value, the radix is 10 (decimal). ![]() For this reason always specify a radix when using parseInt. ECMAScript 5 specifies that 10 (decimal) is used, but not all browsers support this yet. Exactly which radix is chosen is implementation-dependent. If the input string begins with "0", radix is eight (octal) or 10 (decimal).If the input string begins with "0x" or "0X", radix is 16 (hexadecimal) and the remainder of the string is parsed.If radix is undefined or 0 (or absent), JavaScript assumes the following: parseInt should not be used as a substitute for Math.floor(). 6.022e23), using parseInt to truncate numeric values will produce unexpected results when used on very large or very small numbers. Leading and trailing spaces are allowed.īecause some numbers include the e character in their string representation (e.g. parseInt truncates numbers to integer values. If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point. For example, for hexadecimal numbers (base 16), A through F are used. For radices above 10, the letters of the alphabet indicate numerals greater than 9. For example, a radix of 10 indicates to convert from a decimal number, 8 octal, 16 hexadecimal, and so on. If not NaN, the returned value will be the integer that is the first argument taken as a number in the specified radix (base). The parseInt function converts its first argument to a string, parses it, and returns an integer or NaN. If the first character cannot be converted to a number, NaN is returned. Return valueĪn integer number parsed from the given string. Different implementations produce different results when a radix is not specified, usually defaulting the value to 10. Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior. Specify 10 for the decimal numeral system commonly used by humans. radix An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the above mentioned string. Leading whitespace in the string argument is ignored. If the string argument is not a string, then it is converted to a string (using the ToString abstract operation). Syntax parseInt( string, radix) Parameters string The value to parse. The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |