1// parseFloat takes in a string value and converts it to a float
2// The parseFloat function will look at the first character of
3// the string and decided whether that character is a number or not
4// If not the parseFloat function will return Nan
5
6let stringNumber = "8.0"
7
8let floatNuumber = parseFloat(stringNumber);
1 var subtotal = parseFloat(val) + parseFloat(tax) + parseFloat(imp) + parseFloat(env);
2 var subtotal = subtotal.toFixed(2); //two decimal places
1// parseInt
2parseInt("10");//------------ 10
3parseInt("10.00");//--------- 10
4parseInt("10.33")//--------- 10
5parseInt("34 45 66")//------ 34
6parseInt(" 60 ")//------ 60
7parseInt("40 years")//------ 40
8parseInt("He was 40")//----- NaN
9parseInt("10", 10)//-------- 10
10parseInt("010")//----------- 10
11parseInt("10", 8)//--------- 8
12parseInt("0x10")//---------- 16
13parseInt("10", 16)//-------- 16
14// parseFloat
15parseFloat("10")//-----------10
16parseFloat("10.00")//--------10
17parseFloat("10.33")//--------10.33
18parseFloat("34 45 66")//-----34
19parseFloat(" 60 ")//---------60
20parseFloat("40 years")//-----40
21parseFloat("He was 40");//----NaN
22/ mm.mirzaei /
1//parseFloat() parses a string and returns a number. Spaces are allowed. Only the first number is returned:
2
3Example
4
5parseFloat("10");
6parseFloat("10.33");
7parseFloat("10 20 30");
8parseFloat("10 years");
9parseFloat("years 10");