I'm having an issue with the Round function in VBA. I'm aware that it uses Banker's Rounding but the results still seem inconsistent to me:
? Round(1.425, 2)
1.42
? Round(2.425, 2)
2.42
? Round(3.425, 2)
3.42
? Round(4.425, 2)
4.42
? Round(5.425, 2)
5.42
? Round(6.425, 2)
6.42
? Round(7.425, 2)
7.42
? Round(8.425, 2)
8.43
? Round(9.425, 2)
9.43
? Round(10.425, 2)
10.42
? Round(11.425, 2)
11.42
? Round(12.425, 2)
12.42
If I understand Banker's Rounding, all of these should round to x.42 but 8.425 and 9.425 don't. This is in Excel 16.66 for Mac but I've verified it in other products as well.
EDIT
I confirmed the same behaviour occurs in C# as well when I use double
data types. But when I use decimal
, all is right again. Which leads me to believe this is an issue with floating points in VBA.