As Unity uses the .NET runtime, both the
Mathf.Round() methods use “Banker’s Rounding”. This is a rounding system that rounds numbers to the nearest even integer when rounding from the midpoint (.5). The “Banker’s Rounding” approach works best when dealing with large quantities of numbers and exists to avoid rounding error. However, this may be not what you’re expecting when you’re working in Unity!
You can use the .NET
System.Math library in instead of
UnityEngine.Mathf to implement a more conventional rounding system by passing through
MidpointRounding.AwayFromZero as an argument to the
Math.Round method. Be warned that the default for
Round is also “Banker’s Rounding” so if you don’t use this, you will still get the same results as Unity’s version. See below for an example.
You will also need to cast the return to an int, as the
Math.Round method will return a double instead.