1var myInt = parseInt("10.256"); //10
2var myFloat = parseFloat("10.256"); //10.256
1var myInt = parseInt("10.256"); //10
2var myFloat = parseFloat("10.256"); //10.256
1
2parseInt("10"); // returns 10
3
4parseInt("10.33"); // returns 10
5
6parseInt("10 20 30"); // returns 10
7
8parseInt("10 years"); // returns 10
9parseInt("years 10"); // returns NaN
10
1function convertToInterger(mystring) {
2
3 return parseInt(mystring);
4
5}
6
7console.log(convertToInterger("42"));
1var myNumber="120";
2var myString =parseInt(myNumber); //converts string to number return: 120
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