Javascript retains two decimal places and uses toFixed to implement _ javascript skills

Source: Internet
Author: User
Use Math directly. there is a problem with round (x * 100). Sometimes there is a very small error, and many decimal places are displayed. For example, 0.9996*100 will change to 99.96000000000001. What I want is below, if you are interested, refer to Haha Math. round (x * 100)/100, of course I want Math. round (x * 100. But use Math directly. there is a problem with round (x * 100). Sometimes there is a very small error, and many decimal places, such as 0.9996*100, will become 99.96000000000001. This is not what I want.

Find the javascript function. The number type has a toFixed () function to test:

The Code is as follows:


Alert (0.9996*100). toFixed (2 ));


Use Number. toFixed () to display any decimal places!
Related Article

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.