C#中的舍入数字远离0#

use*_*206 1 c# math rounding winforms

我做了一些研究,发现了Math.RoundMidpointRounding.AwayFromZero方法.

第二种方法做我想要的但我不明白使用它的语法.

例如,如果您有double5.5并且想要使用正常舍入来获得6,而将4.4用于获得4,那将如何完成?

Cri*_*scu 5

一些重载Math.RoundMidpointRounding值作为参数.

你可以写:

Math.Round(2.225m, 2, MidpointRounding.AwayFromZero)
Run Code Online (Sandbox Code Playgroud)

那个表达式会评估为2.23.