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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use Decimal datatype in VBA

Status
Not open for further replies.

Eldaria

Programmer
Sep 20, 2001
123
NL
Hi people,

How can I dim a variable to become an decimal datatype. I need as many decimal points as I can because of a precise calculation.
I have this now and as you can see I used Double as it appears to give the longest decimal place.

Function giveperc(CalcType As Integer, Template As Long, Cat As Long, Score As Double) As Double

But... it is not long enough.. I did a Manual calculation after and it gives close values but not close enough I had on the end variations up to 5%, and it can only have to do with the fact that it is rounding the numbers.

The function above returns a Value that get's used in a create table Query, and I tried to look what type it creates the field as, and it creates it as a Number/Double.

How do I get more decimals? I know there is a 14Byte datatype that is called Decimal, but I do not have it as a selection in VBA, only in the Tables...
Eldaria

That was my 25cent** of opinion.

** Inclusive Intrest, tax on interest, Genral tax, Enviromental tax, Tax, and tax on intrest, tax on fees, tax on tax, and other Various taxes and fees.
 
Hi,

I got this from help:

At this time the Decimal data type can only be used within a Variant, that is, you cannot declare a variable to be of type Decimal. You can, however, create a Variant whose subtype is Decimal using the CDec function. Hope this is ok. If not, just let me know.

Nick (Everton Rool OK!)
 
Double is EXTREMELY accurate. It is capable of handling upto 324 decimal places. It makes it seem that your code is the problem.

Can you post the code and i'll have a look.

Craig
 
Nope, sorry, I just tried that now...
and when it creates the table It uses Text datatype for that field, and the information get's corrupted...
Eldaria

That was my 25cent** of opinion.

** Inclusive Intrest, tax on interest, Genral tax, Enviromental tax, Tax, and tax on intrest, tax on fees, tax on tax, and other Various taxes and fees.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top