How to Use IEEE Standard for binary floating point operations in JavaScript to generate inexplicable errors _ javascript skills

Source: Internet
Author: User
When javascript performs a decimal computation, there will be a cycle of 9. The following methods help solve the problem. When javascript performs a decimal computation, there will be a cycle of 9. The following methods help solve the problem.

The first parameter is the value to be processed, and the second parameter is the number of decimal places to be retained. This is the case in your project ~

The Code is as follows:


Function round (v, e ){
Var t = 1;
For (; e> 0; t * = 10, e --);
For (; e <0; t/= 10, e ++ );
Return Math. round (v * t)/t;
}

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.