This is because the default type used in your example is System.Double
,
99.804.GetType()
>>>>IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Double System.ValueType
In your particular case, what you want to use is System.Decimal
which is more precise,
[decimal]99.804-[decimal]99.258
>>>>0.546
or alternatively,
99.804d-99.258d
>>>>0.546
Further information
I felt the need to clarify what I meant by more precise. Basically, it is important to understand that double
type has a much more larger range than decimal
type. But, larger range doesn't mean more accurate.
Actually, System.Decimal
was initially created to take care of currency/money problem where decimal point can be a mess. It's preciseness rely in the fact that it uses base-10 math instead of base-2 math for System.Double
. Obviously, the latter is much more efficient to calculate but less accurate.
This can be validated here in the MSDN documentation where it states that,
You can use Decimal
variables for money values. The advantage is the precision of the values. The Double
data type is faster and requires less memory, but it is subject to rounding errors. The Decimal
data type retains complete accuracy to 28 decimal places.
Floating-point (Single
and Double
) numbers have larger ranges than Decimal
numbers but can be subject to rounding errors. Floating-point types support fewer significant digits than Decimal
but can represent values of greater magnitude.