2

I have a question about the Mathf.RoundToInt()

int val = Mathf.RoundToInt(10.5f);
val = Mathf.RoundToInt(9.5f);
val = Mathf.RoundToInt(8.5f);

The above generates "10, 10, 8" not "11, 10, 9".

According to the reference manual of Unity, Mathf.RoundToInt() returns "even value" when the 1st decimal place is "5" (e.g. 8.5 -> 8.0).

I would like to know the reason why the Mathf.RoundToInto() return like this, not like normal rounding (e.g. 8.5 ->9.0, 9.5 -> 10.0).

4

1 回答 1

5

来自http://en.wikipedia.org/wiki/Rounding#Round_half_to_even

对于 [...] 值的合理分布,四舍五入数字的预期(平均值)与原始数字的预期(平均值)相同。

于 2013-10-30T00:13:48.090 回答