View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Data Types and inaccuracies with Trig functions in VBA

Peter,

From a Myrna Larson post:
'-----------------------------------
The decimal data type is a subtype of a variant. You must Dim the variable as a
variant, then put the data into it with the CDec function. Since Decimals can
have up to 28 significant figures, and doubles are limited to 15 or 16, how do
you assign a literal value to one? From a string representation of the number,
i.e.
Dim Dec As Variant
Dec = CDec("1234567890123456789012345678")
Debug.Print Dec, TypeName(Dec)
'------------------------------------
From a Chip Pearson post:
To display these values on a worksheet, you'll have to change them to
strings to prevent Excel from rounding them ...
Range("C2").Value = " ' " & CStr(Dec)
'-----------------------------------

Regards,
Jim Cone
San Francisco, CA

"Peter M" wrote in message
...
I am developing an application to calculate navigation data from Sun & Star
sights (interesting for sailors, boring for everyone else).
The problem is that I appear to be getting small inaccuracies when
calculating angles. I have used Double as the data type. Looking through
the help files I note that there should be a 'Decimal' data type that uses
many more digits so potentially improving accuracy. However, a line such
as:
Dim dLat as Decimal
results in a message: 'Compile error: Expected: New or type name'
I understand that this is saying it doesn't recognise the Decimal data type.
Do I have to add a library to use this? if so which one?
Any ideas gratefully received.
Peter Morris