Morten Wennevik said:
Just to add to the other posts,
I think the problem is that the system actually reads 4.499999999...
something when input 4.5 so the rounding is as far as the computer knows
"correctly" done to 4.0, even though this is not the desired result.
No - 4.5 itself is exactly representable, even in a binary floating
point number (although what was actually presented was decimal.Round,
which deals with decimal floating point numbers).
The "problem" is that decimal.Round (and the other Round methods)
perform banker's rounding. From the docs:
<quote>
When d is exactly halfway between two rounded values, the result is the
rounded value that has an even digit in the far right decimal position.
For example, when rounded to two decimals, the value 2.345 becomes 2.34
and the value 2.355 becomes 2.36. This process is known as rounding
toward even, or rounding to nearest.
</quote>