我有一个关于 Mathf.RoundToInt() 的问题
int val = Mathf.RoundToInt(10.5f);
val = Mathf.RoundToInt(9.5f);
val = Mathf.RoundToInt(8.5f);
上面生成的是“10,10,8”而不是“11,10,9”。
根据Unity的引用手册,当小数点后第一位为“5”时(例如8.5 -> 8.0),Mathf.RoundToInt() 返回“偶数”。
我想知道为什么 Mathf.RoundToInto() 像这样返回,而不是像正常舍入那样返回(例如 8.5 -> 9.0、9.5 -> 10.0)。
最佳答案
来自http://en.wikipedia.org/wiki/Rounding#Round_half_to_even :
For reasonable distributions of [...] values, the expected (average) value of the rounded numbers is the same as that of the original numbers.
关于algorithm - Mathf.RoundToInt() 的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19671523/