Many time we developed any webpage sometime there is a requirement where we need to convert string to a number, it is a very simple process to do it Javascript provides its own string to number converter function.

Jquery convert string to number
1 | var str_val = '234' ; |
2 | var num_val = parseInt(str_val); |
1 | parseInt(string, radix) |
If you don't pass the radix parameter Javascript or leave it 0, then in this case javascript behaves like this.
- If the string is not empty and begins with any value then radix would be 10 (Decimal) or 8 (octal).
- If the string begins with '0x' or '0X' (Uppercase and lowercase), then the radix would be 16 (Hexadecimal).
If the given string is not get converted into an integer value, parseInt() returns NaN value. Some best Example
parseInt('123_456')
// 123
Still, if you have any doubt, feel free to comment below.
Post a Comment