Difference between CDec and CDbl

J

James

i meant the technical differences... what does one read that the other
cannot? Thanks.
 
J

Josip Medved

i meant the technical differences... what does one read that the other
cannot? Thanks.

Since both decimal as double are numeric types, I doubt that there is
any difference, as in from what they can convert, but there is big
difference in types to which they convert to.
 
J

Jay B. Harlow [MVP - Outlook]

In addition to the other comments:

CDec returns a Decimal value.

CDbl returns Double value.

As you may know TypeOf Decimal IsNot TypeOf Double. Decimal is a base 10
floating point number, while Double is a base 2 floating point number. They
have different precisions & ranges.

If you have Option Strict On (you do have Option Strict On don't you)
attempting to use CDbl and assign it to a Decimal will cause a compile
error. While attempting to use CDec and assign it to a Double will cause an
implicit conversion from Decimal to Double (read it will work, but you
really did CDbl(CDec(?)).
 
J

James

As you may know TypeOf Decimal IsNot TypeOf Double. Decimal is a base 10
floating point number, while Double is a base 2 floating point number. They
have different precisions & ranges.


Can you explain this a little more? I work well with examples and I
don't really understand what you're saying here. Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top