You can try this:
int Roundoff(float num) {
return num < 0 ? (int) (num - 0.5) : (int) (num + 0.5);
}
There is a trick with negative values (you can't just add 0.5
):
-13.9 -> -14.0
-13.1 -> -13
And be careful, since
int.MaxValue < float.MaxValue
int.MinValue > float.MinValue