📜  Math.Floor() 和 Math.Truncate() 之间的区别 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:15.881000             🧑  作者: Mango

代码示例1
// Math.Floor rounds down
// Math.Ceiling rounds up
// Math.Truncate rounds towards zero

Round(1.5) = 2
Round(2.5) = 2
Round(1.5, MidpointRounding.AwayFromZero) = 2
Round(2.5, MidpointRounding.AwayFromZero) = 3
Round(1.55, 1) = 1.6
Round(1.65, 1) = 1.6
Round(1.55, 1, MidpointRounding.AwayFromZero) = 1.6
Round(1.65, 1, MidpointRounding.AwayFromZero) = 1.7

Truncate(2.10) = 2
Truncate(2.00) = 2
Truncate(1.90) = 1
Truncate(1.80) = 1