1var myInt = parseInt("10.256"); //10
2var myFloat = parseFloat("10.256"); //10.256
1function convertToInterger(mystring) {
2
3 return parseInt(mystring);
4
5}
6
7console.log(convertToInterger("42"));
1var myInt = parseInt("12.345");
2//myInt = 12
3
4var myFloat = parseFloat("12.345");
5//myFloat = 12.345
6
7var myFloat = parseFloat("12.345,50"); //<-- pay attention!
8//myFloat = 12.345
9
10var myFloatCrazy = parseFloat(0.1+0.2); //<-- pay MORE attention!
11//myFloat = 0.30000000000000004
12
1parseInt(string, radix);
2
3console.log(parseInt(' 0xF', 16));
4// expected output: 1500
5
6console.log(parseInt('321', 2));
7// expected output: 0
8
9console.log(parseInt('321', 10));
10// expected output: 321
11
12/*
13 * @param string Required. The value to parse. If this argument is not
14 * a string, then it is converted to one using the ToString abstract
15 * operation. Leading whitespace in this argument is ignored.
16 *
17 * radix
18 * @param radix Optional. An integer between 2 and 36 that represents
19 * the radix (the base in mathematical numeral systems) of the string.
20 * Be careful—this does not default to 10!
21 * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt#Description
22 * for what happens when radix is not provided
23 */