How to Convert Text to Integers in JavaScript
Text strings may be converted to Integers in JavaScript using the parseInt(string, radix); function. The radix parameter is used to specify which numeral system to be used, for example : radix 2 = binary, radix 8 = octal, radix 10 = decimal and radix 16 = hexadecimal. If the string is not a number, then the function returns NaN. If the radix is omitted then the numeral system is assumed to be decimal.
Instructions
-
-
1
Convert a string to an integer (binary). For example:
parseInt("11111111", 2) = 255;
-
2
Convert a string to an integer (decimal). For example:
parseInt("255", 10) = 255;
-
-
3
Convert a string to an integer (hexadecimal). For example:
parseInt("FF", 16) = 255;
-
1
References
- Photo Credit Hemera Technologies/AbleStock.com/Getty Images