jQuery - Convert string to integer
Find code to convert String to Integer using jQuery. To convert, use JavaScript parseInt() function which parses a string and returns an integer.
Related Post:
The syntax of parseInt() function is,
It takes 2 parameters. First parameter is value which needs to be converted. And second parameter "radix" is used to specify which numeral system to be used, for example, a radix of 16 (hexadecimal) indicates that the number in the string should be parsed from a hexadecimal number to a integer number.
If the radix parameter is omitted, JavaScript assumes the following:
If you string contains spaces then only first number will be returned.
This function will only return "NaN", if the first character cannot be converted to a number.
1 | var sVal = '234' ; |
2 | var iNum = parseInt(sVal); //Output will be 234. |
The syntax of parseInt() function is,
1 | parseInt(string, radix) |
If the radix parameter is omitted, JavaScript assumes the following:
- If the string begins with "0x", the radix is 16 (hexadecimal)
- If the string begins with any other value, the radix is 10 (decimal)
If you string contains spaces then only first number will be returned.
1 | var sVal = '23 45 68' ; |
2 | var iNum = parseInt(sVal); //Output will be 23. |
Read More Articles
0 Comments:
Posting Komentar