Rounding half down a decimal

后端 未结 3 1152
借酒劲吻你
借酒劲吻你 2021-01-25 07:52

Does an equivalent of Java RoundingMode.HALF_DOWN exist in C#?

For example, I want to round 1.265 to 1.26, and 1.266

3条回答
  •  梦毁少年i
    2021-01-25 08:46

    Use the .Round method with the following constructor overload:

    public static double Round (double value, int digits, MidpointRounding mode);
    

    Calling like so:

    Math.Round(value, 2, MidpointRounding.AwayFromZero);
    

    Here's full documentation.

提交回复
热议问题