1 |
There are JavaScript functions (not string methods) that convert strings to numbers
|
2 |
parseInt("15") or equivalently parseInt("15",10) both return the number 15 in base 10
|
3 |
The optional second argument is the desired radix so that parseInt("15",8) returns 17 in octal
|
4 |
If input string begins with "0x" the default radix is 16 (hexadecimal) whereas if it begins with "0" the default radix is 8 (octal) Ñ otherwise, the default radix is 10
|
5 |
x = 1 + "1"; // evaluates to "11"
|
6 |
x = 1 + parseInt("1"); // evaluates to 2
|
7 |
parseFloat(string) returns a floating point value
-
var x = "0.0314E+2"; var y = parseFloat(x); // sets y=3.14
|
8 |
On platforms that support it, parseInt and parseFloat return NaN (Not a Number) if parsing fails
|