About C # Math,

Source: Internet
Author: User

About C # Math,

In other words, the last time the System Maintenance System Used JS to read the experiment data imported into Excel, it was automatically rounded down. Then I came to the customer's site to hear the customer's feedback about the Excel experiment data requirements.

On the basis of the statistical analysis, the concept of "odd-in-even-out" is more scientific than that of "Rounding-in". In a large number of computations, it makes the mean of the result error after rounding tend to zero, instead of entering the result every five as rounding, leading to a large number of results, which leads to accumulation of errors and system errors, "odd-in-even-house" minimizes the impact of rounding errors on the measurement results.

Math finds out, uses the Round overload, and uses MidpointRounding. ToEven to achieve odd-in-even.

// 4 double d = 5.214; double res = Math. round (d, 2, MidpointRounding. toEven); Console. writeLine (res); // 5.21 // 6 d = 5.216; res = Math. round (d, 2, MidpointRounding. toEven); Console. writeLine (res); // 5.22/5 d = 5.215; res = Math. round (d, 2, MidpointRounding. toEven); Console. writeLine (res); /// 5.22 d = 5.225; res = Math. round (d, 2, MidpointRounding. toEven); Console. writeLine (res); // 5.22 // more than 3 digits after the decimal point, d = 0.7865666; res = Math. round (d, 2, MidpointRounding. toEven); Console. writeLine (res); /// 0.79 d = 0.786; res = Math. round (d, 2, MidpointRounding. toEven); Console. writeLine (res); /// 0.79 d = 0.785; res = Math. round (d, 2, MidpointRounding. toEven); Console. writeLine (res); // 0.78.

 

 

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.