Using Visual Studio 2017, create a VB.net project, and run the following lines of code:
Dim a As Double = 0.52
Dim value As Double
value = a * 3 'value = 1.56
value = value + 1 'value = 2.56
value = value + 2 'value = 4.5600000000000005
Console.WriteLine(value) '4.56
If you put a break point before addition of 2 to value, you can see value holds 4.5600000000000005 instead of 4.56.
Why does the value have the trailing 0.0000000000000005 after addition of 2 to it? And more importantly, how do I handle the trailing inaccuracies?
That inaccuracy can be magnified if I perform multiplication and will surely screw up my end result.