50 Différence entre Math.Floor() et Math.Truncate()

Quelle est la différence entre Math.Floor() et Math.Truncate() dans .NET ?

请先 登录 后评论

1 réponses

Marek Grzenkowicz

Quelques exemples :

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
请先 登录 后评论