3 回答

TA貢獻2065條經(jīng)驗 獲得超14個贊
Math.Round
返回值
類型:System.Double 如果a的分數(shù)分量介于兩個整數(shù)之間,其中一個是偶數(shù),另一個是奇數(shù),則返回偶數(shù)。注意,此方法返回 Double
而不是整型。 評語
這種方法的行為遵循IEEE標準754,第4節(jié)。這種四舍五入有時被稱為四舍五入到最近,或銀行家的四舍五入。它最大限度地減少了由在單個方向上一致舍入中點值而產(chǎn)生的舍入誤差。
Math.Round
MidpointRounding
MidpointRounding
Round(Decimal, Int32)
/Round(Decimal, Int32, MidpointRounding)
Round(Double, Int32)
/Round(Double, Int32, MidpointRounding)
MidpointRounding
RoundingMode

TA貢獻1878條經(jīng)驗 獲得超4個贊
(MidpointRounding.ToEven)
向負無窮遠的方向發(fā)展。 正無窮大。 向上或向下都是零。 ,其舍入到最接近的整數(shù)或指定的小數(shù)位數(shù)。如果行為在兩種可能性之間完全相等,例如舍入,則可以指定行為,以便最后的數(shù)字是偶數(shù)(“ Round(2.5,MidpointRounding.ToEven)
“變得更遠,離零更遠” Round(2.5,MidpointRounding.AwayFromZero)
“成為3)。
-3 -2 -1 0 1 2 3 +--|------+---------+----|----+--|------+----|----+-------|-+ a b c d e a=-2.7 b=-0.5 c=0.3 d=1.5 e=2.8 ====== ====== ===== ===== =====Floor -3 -1 0 1 2Ceiling -2 0 1 2 3Truncate -2 0 0 1 2Round(ToEven) -3 0 0 2 3Round(AwayFromZero) -3 -1 0 2 3
Round
n = 3.145;a = System.Math.Round (n, 2, MidpointRounding.ToEven); // 3.14b = System.Math.Round (n, 2, MidpointRounding.AwayFromZero); // 3.15
c = System.Math.Truncate (n * 100) / 100; // 3.14d = System.Math.Ceiling (n * 100) / 100; // 3.15

TA貢獻1848條經(jīng)驗 獲得超10個贊
如果a的分數(shù)分量介于兩個整數(shù)之間,其中一個是偶數(shù),另一個是奇數(shù),則返回偶數(shù)。
這種方法的行為遵循IEEE標準754,第4節(jié)。這種四舍五入有時被稱為四舍五入到最近,或銀行家的四舍五入。它最大限度地減少了由在單個方向上一致舍入中點值而產(chǎn)生的舍入誤差。
MidpointRounding
- 3 回答
- 0 關(guān)注
- 825 瀏覽
添加回答
舉報