Definition and usage
The tofixed () method rounds a number to a specified number of decimal places.
Syntax
Numberobject. tofixed (Num) num is required. Specifies the number of digits in a decimal place, ranging from 0 ~ Values between 20, including 0 and 20. Some implementations support a larger value range. If this parameter is omitted, it is replaced by 0.
Return Value
Returns the string representation of numberobject. Without the exponential notation, there is a fixed num digit after the decimal point. If necessary, the number is rounded off, or 0 can be used to make up for the specified length. If num is greater than LE + 21, this method only calls numberobject. tostring () and returns the string represented by exponential notation.
Throw
When num is too small or too large, an exception rangeerror is thrown. 0 ~ The value between 20 does not cause this exception. Some implementations support values in a larger or smaller range.
If the object that calls this method is not a number, a typeerror error is thrown.
Instance
CopyCodeThe Code is as follows: <SCRIPT type = "text/JavaScript">
VaR num = newnumber (13.37 );
Document. Write (Num. tofixed (1 ))
</SCRIPT>
Result: 13.4
Correction of the tofixed () method in the system using JavaScript