How to Convert Text to Integers in JavaScript

How to Convert Text to Integers in JavaScript thumbnail
Use JavaSctipt to convert strings to integers.

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;

Related Searches:

References

  • Photo Credit Hemera Technologies/AbleStock.com/Getty Images

Comments

You May Also Like

  • Tutorial on JavaScript Databases

    A JavaScript program runs within the Web browser. For security reasons, JavaScript cannot write to a local computer, other than using temporary...

  • How to Change Form Action Using JavaScript

    Most HTML forms have a hard-coded action URL that rarely needs to be changed. An action URL is nothing more than the...

  • JavaScript Text Tutorial

    JavaScript is a scripting language used in many computer programs, browsers and websites. Webmasters and programmers use JavaScript to create menus, calculators...

Related Ads

Featured