Javascript tofixed () method

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.