The true Meaning of Math.Round () in C #

Source: Internet
Author: User

I stepped on a hole today.
Math.Round () function rounding found wrong, 3/2 = 2, 5/2 = 2
Search the Internet: http://www.cnblogs.com/fanyong/archive/2013/05/30/chinese_round.html

Math.Round () in C # is not a "rounding" method used. In fact, in VB, VBScript, C #, J #, T-SQL round functions are used banker ' s rounding (banker algorithm), namely: four six into the five to take the pair. In fact, this is also an IEEE specification, so all IEEE compliant languages should adopt such an algorithm.

Starting with. NET 2.0, the Math.Round method provides an enumeration option Midpointrounding.awayfromzero can be used to implement "rounding" in the traditional sense. namely: Math.Round (4.5, Midpointrounding.awayfromzero) = 5.

The true Meaning of Math.Round () in C #

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.