Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unexpected behaviour with Round() function
#1
Hi Gintaras
This code with QM 2.3.0.1:
out Round(0.5 0)
out Round(1.5 0)
out Round(2.5 0)
out Round(3.5 0)
out Round(4.5 0)
out Round(5.5 0)
out Round(6.5 0)
out Round(7.5 0)
out Round(8.5 0)

Produces this output:
0
2
2
4
4
6
6
8
8

Which is not what I was expecting.
Cheers,
John
#2
Internally it just calls Windows API function VarR8Round. I don't know why VarR8Round rounds 0.5 to the nearest even number. Maybe it is better in certain cases. For example, if you do many Round with money, and everytime 0.5 would be rounded up, and then add all, then the final result (sum) would be too big. Now, when in ~50% cases it rounds up and in ~50% cases rounds down, the final result (sum) is more correct.

For example. With your numbers. Without Round the sum is 40.5. With Round it is 40. Now calculate how much it would be if Round rounds 0.5 only up or only down.


Forum Jump:


Users browsing this thread: 1 Guest(s)