Math. Round rounded

Source: Internet
Author: User
Tags rounds
In math. when performing data processing, round often encounters a situation where 81.25 retains a decimal number, and the value is 81.2. It is searched by material and math. the round rounding algorithm adopts the banker's rounding algorithm, which is a standard stipulated by IEEE. It is called the banker rounding method, the essence is a four homes six into five get even (also known as four homes six into five stay double) method. The rule is: when the value of the deviation is less than 5, the deviation is directly performed. When the value of the deviation is greater than or equal to 6, the deviation is performed first while the deviation is performed; when the value of the deprecated digit is equal to 5, if the value of the forward digit is odd, the value is rounded up to the forward digit. If the value of the forward digit is even, the value is directly rounded up. The math. Round overload list is learned through msdn.
Math. Round (decimal): rounds a small value to the nearest integer. Supported by. NET Compact framework.
Math. Round (double): rounds the double-precision floating point value to the nearest integer. Supported by. NET Compact framework.
Math. Round (decimal, int32): round a small value to a specified precision. Supported by. NET Compact framework.
Math. Round (decimal, midpointrounding): round a small value to the nearest integer. A parameter that specifies how to round a value when it is in the middle of the other two numbers.
Math. Round (double, int32): rounds the double-precision floating point value to the specified precision. Supported by. NET Compact framework.
Math. Round (double, midpointrounding): rounds the double-precision floating point value to the nearest integer. A parameter that specifies how to round a value when it is in the middle of the other two numbers.
Math. Round (decimal, int32, midpointrounding): round a small value to a specified precision. A parameter that specifies how to round a value when it is in the middle of the other two numbers.
Math. Round (double, int32, midpointrounding): rounds the double-precision floating point value to the specified precision. A parameter that specifies how to round a value when it is in the middle of the other two numbers.
Msdn
The following is an example to learn more.
    Math.Round(0.145, 2, MidpointRounding.AwayFromZero)    Math.Round(0.145, 2, MidpointRounding.ToEven)
Running result:
    0.14    0.14
This is a very surprising result, because we call the double overload of math. round, and we need to call the decimal overload.
    Math.Round((decimal)0.145, 2, MidpointRounding.AwayFromZero)    Math.Round((decimal)0.145, 2, MidpointRounding.ToEven)
Running result:
    0.15    0.14
Let's take a look at the following: midpointrounding
Toeven: When a number is the center of the other two numbers, it is rounded to the nearest even number.
Awayfromzero: When a number is the median of the other two numbers, it is rounded to a value with a smaller absolute value.

By default, toeven is used, which can be found in the above Code.


In the SQL Server database also has a similar situation, in the development process, write the function to process this situation, you can refer to the http://blog.csdn.net/mh942408056/article/details/8234320

Math. Round rounded

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.