Doubles

jglobe

Member
Joined
Aug 27, 2005
Messages
12
Programming Experience
1-3
Im trying to store

-87.872449938533194 into a double array but turns into
-87.8724499385332

This does not...
-87.872449938533191

If I type -87.872449938533194 in the VS IDE it automatically turns it into
-87.87244993853332

any help would be appreciated.
 
Floating-point numbers are prone to round-off issues. Read up on the fixed-point Decimal type, which has no round-off issues, to see if it is suitable for your needs.
 
This will solve your problem

Use decimal Instead of double
 
If you're talking C++.NET then you can use the System.Decimal structure just like you can in VB.NET or C#, or any .NET language, because it is part of the Framework. If you're talking unmanaged C++, I'm not sure there is one, although that's not definitive.
 
Just had a quick look on MSDN and it looks like the closest thing is the CURRENCY data type, which can be wrapped in the CComCurrency class. The problem is that, because it is designed for currency calculations specifically, it only has four digits to the right of the decimal point.
 
Back
Top