C # rounding

Source: Internet
Author: User

Reprinted from: http://dlix.bokee.com/5956750.html

C #, java, and vbscriptFour Homes, six in five into two (explained below).
SQL server uses rounding.

C # For example, Math. Round (1.25, 1) = 1.2.

In SQL, select round (1.25, 1) returns 1.3.

Reference code for rounding in C:

For example, if 2.45 is to be rounded to the last decimal place, you can first give 2.45*10, then add 0.5, then get the integer, and then divide it by 10.

Public double C1Round (double value, int digit)
{
Double vt = Math. Pow (10, digit );
Double vx = value * vt;

X + = 0.5;
Return (Math. Floor (vx)/vt );
}

Four Homes, six in five into double 

Four Homes, six in five into two is an accurate counting retention method. the rounding rule is "four homes six into five into two". Here "four" means less than five, and "six" means more than five, "5" is the ending number of the rounded bits. If we look at the first bid, we will not enter the odd bid, just like 1.25. Because 2 is an even bid, It is 1.2. Another example is 1.35. Because 3 is an odd number, it is 1.4. Obviously, this is required for data statistics.

From a statistical point of view, "four homes, six homes, five into two" is more scientific than "four homes and five into five", which makes some of the results after rounding bigger, some smaller, more even. instead of rounding in five, the result tends to be large.
For example, if the value is 1.15 + 1.25 + 1.35 + 1.45 = 5.2, if the number is rounded to a decimal place
1.2 + 1.3 + 1.4 + 1.5 = 5.4
According to the calculation of "four homes, six in five into two", 1.2 + 1.2 + 1.4 + 1.4 = 5.2, the rounding result can better reflect the actual results

 

Author: Ice dish
Source: http://www.cnblogs.com/icebutterfly/
Copyright: The copyright of this article is shared by the author and the blog
Reprinted: you are welcome to reprinted. To save the author's Creative Enthusiasm, please [reprinted] As required. Thank you.
Requirement: This statement must be retained without the consent of the author; the original text connection must be provided in the article; otherwise, the legal liability must be investigated.

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.