The C # rounding round function uses

Source: Internet
Author: User
The round function in C # is actually not a real rounding function, the general programming language of the round function is not a rounding function, but the banker rounding function, that is, "four homes six into five considerations, five non-zero into one, five after the zero look at the odd couple, five ago for I should give up, five before the odd to enter a"

Using System;  public class example{public   static void Main ()   {      double[] values = {2.125, 2.135, 2.145, 3.125, 3.135, 3.145 };      foreach (double value in values)         Console.WriteLine ("{0}--and {1}", Value,                           math.round (value, 2, Midpointrounding.awayfromzero));}     } The example displays the following output://2.125--2.13//2.135--2.13//2.145--       2.15//
 3.125--3.13//       3.135-3.14//       3.145-3.15
  • 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: 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.