// why does this code gives this value? // shouldn't that the value be 0.9D ?
double test = 360.9D;
test -= 360D;
// test = 0.89999999999997726
This is due to inherent floating point imprecision that occurs when you want to store fractional base-10 numbers in binary. Wikipedia provides a good explanation
Basically you can't store all fractional base-10 numbers exactly in binary. The fractional portion is made up of sums of 2^n where n is a negative integer.
So to approximate 0.9, it will be 1/2 + 1/4 + 1/8 + 0/16 + 0/32 + 1/64 + ... and so on until the sum approximates 0.9, but you can see that the series will never exactly equal 0.9.