Math.Floor() 和 Math.Truncate() 的区别 [英] Difference between Math.Floor() and Math.Truncate()
问题描述
Math.Floor()
和 Math.Truncate()
在 .NET 中?
What is the difference between Math.Floor()
and Math.Truncate()
in .NET?
推荐答案
Math.Floor
向下取整,Math.Ceiling
向上取整,Math.Truncate
向零舍入.因此,Math.Truncate
对于正数就像 Math.Floor
,对于负数就像 Math.Ceiling
.这是参考.
Math.Floor
rounds down, Math.Ceiling
rounds up, and Math.Truncate
rounds towards zero. Thus, Math.Truncate
is like Math.Floor
for positive numbers, and like Math.Ceiling
for negative numbers. Here's the reference.
为了完整性,Math.Round
舍入到最接近的整数.如果该数字正好位于两个整数的中间,则它会向偶数四舍五入.参考.
For completeness, Math.Round
rounds to the nearest integer. If the number is exactly midway between two integers, then it rounds towards the even one. Reference.
另见:Pax Diablo 的回答.强烈推荐!
这篇关于Math.Floor() 和 Math.Truncate() 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!