Javascript--toFixed () function
1. toFixed (n) limit the number of digits after the decimal point, rounded. N:0~20.
2. The action object must be number and 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 #.
Grammar
Parsefloat () Converts a string to a floating-point number
The ToFixed () method rounds numbers to a number that specifies the number of decimal digits
Parameters
The parsefloat () parameter is the string to be converted
ToFixed () Specifies the number of decimal places, which are values between 0 and 20, including 0 and 20, and some implementations can support a larger range of values. If this argument is omitted, 0 is used instead
return value
Converted Numbers
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>"); thedocument.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>
Javascript--toFixed () function