Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Double Data Types

Status
Not open for further replies.

NSNewey

Programmer
Jun 29, 2005
125
GB
Hi,

I've been scathing my head because a function that returns a Double has been giving me a strange result.

I have realised it's VBA and not my function which is at fault.

Can someone tell me why when you type...
?CDbl(110.4) - CDbl(110)
into the intermediate window the result is 0.400000000000006

I have now converted the function's return value using CDec() which returns 0.4 as I would expect.

Is there another way?

 


You need to read up on Floating Point Precision.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
How are ya NSNewey . . .

Try:
Code:
[blue]? CCur(110.4) - CCur(110)[/blue]
Ahhhhh Hahhhhh!

[blue]SkipVought[/blue] is right! [thumbsup2] You need to read up on Floating Point Precision.

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Or, if you know how the parser works:

? cdec(110.4) - 110

or

? 110.4 - cdec(110)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top