1. toFixed (n) limit the number of digits after the decimal point, rounded . N:0~20.
2. The Action object must be numberand cannot be a different type. such as (8.001). toFixed (2) return to 8.00;
3. ToFixed (n) the return value is of type String , and it is wrong to make the size as a number.
4. Parsefloat ("number") and parseint ("numbers") read the first encounter in the string (for example, 91.2w3 the first number is 91.2) and convert to a float or int, the return type is #.
1 <!DOCTYPE HTML>2 <HTML>3 <Scriptsrc= "Http://code.jquery.com/jquery-latest.js"></Script>4 <Head>5 <MetaCharSet= "Utf-8">6 <title>ToFixed ()</title>7 </Head>8 <Body>9 </Body>Ten <Scripttype= "Text/javascript"> One varA0= 8.01. toFixed () A varA1=parsefloat ("8.006"). toFixed (2); - varA2=parsefloat ("9.091"). toFixed (2); - document.write ("A0 Type:"+typeof(A0)+"<br>"); the document.write ("A1 Type:"+typeof(A1)+"<br>"); - document.write ("A2 Type:"+typeof(A2)+"<br>"); - document.write ("A0:"+A0+"<br>"); - document.write ("A1:"+A1+"<br>"); + document.write ("A2:"+A2+"<br>"); - document.write ("A1 is less than A2?:" +(A1<A2)+ "<br>"); + </Script> A </HTML>
1 Output Value: 2 a0 Type: string 3 A1 Type: string 4 A2 Type: string 5 A0:8 6 a1:8.01 7 a2:9.09 8 true ps:8.01 vs 9.09
Javascript--toFixed () function