With the new Euro currency it is important to know that the rounding rules used in VB DO NOT CONFORM to the rounding rules that must be applied when converting to and from the Euro.
The rules that must be applied for Euros are as follows:
When rounding to an x number of decimals, the last decimal must be:
- Rounded down (i.e. left alone) when the following decimal (if any) is 4 or less.
- Rounded up when the following decimal is 5 or more.
E.g. if rounding to 2 decimal places:
1.23432 rounds to to 1.23
3.39820982 to 3.40
2.285 to 2.29
2.275 to 2.28
VB ,however, conforms to the so-called "Computer's Rule".
Even though the "Computer's Rule" is very similar to the rule used for converting Euros, it is different in one significant aspect.
If after the digit that is to be rounded, the digits following are exactly equal to 5, the value is rounded to the NEAREST EVEN NUMBER.
This will cause such "strange" results as the following:
If rounding to an integer:
0.5 rounds to 0
1.5 rounds to 2
2.5 rounds to 2
3.5 rounds to 4
4.5 rounds to 4
Or, as in the previous example:
2.285 rounds to 2.28, not to 2.29 as it should for Euro conversions.
I'm posting this because it is important that people are aware of this feature of VB and must make sure they work around it if they want to write Euro-compliant code. I'll add comments with some suggestions of code that people can use to ensure this compliance. Because I'm adding suggestions myself I will rate this question 0 points but comments are welcome.