When I run this code with the decimal places constant set to 1, I get what I expected: d1 is set to 1.3 and d2 is set to 301.5. However if I change it to 2, I do not get what I expected: d1 is set to 1.24, but d2 remains unchanged at 301.4499999999999886. I even tried with 301.4499 and I still ended up with the same big bloody number!
Double notes:
Double is an IEEE double-precision, floating-point value. This means it is speedy but has some limits for values it can contain. For more information, refer to the wikipedia page about floating point.
perhaps at some instant during those operations it was a “correct” value (based on your expectations), but because you are moving from double to double with a double divide… all bets are off… just a Alberto indicated.
Use Format with the correct number of decimal places when you display the value. Nothing is inherently wrong with your results, just be aware of the limitations of double and work with them.