dim as double (1 Viewer)

AljayB

Registered User.
Local time
Yesterday, 16:03
Joined
Dec 2, 2015
Messages
19
Hello,

Can some one please help me, I want to perform a calculation.
I have attached the file.

It works fine with whole numbers, however I want to be able to add decimal places to my numbers and I have tried to dim as Decimal, but it wont let me, what did I do wrong?
for my calculation to work I need decimal places in the insert fields aswell as in my resoult field.

please help.

thank you
 

Attachments

  • izracun.PNG
    izracun.PNG
    19.3 KB · Views: 50

Ranman256

Well-known member
Local time
Yesterday, 19:03
Joined
Apr 9, 2015
Messages
4,337
make sure the text box format property is fixed, 2.
If integer or unassigned, you will not get decimals.
 

AljayB

Registered User.
Local time
Yesterday, 16:03
Joined
Dec 2, 2015
Messages
19
I have assigned the text box to format fixed and the text box is also assigned to a control source in my table.
The vba code still shows red when I try to dim as decimal,
also when I try to type a number like 0.3321 in my text box it doesn't get stored it only shows 0.0000

what did I miss?
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 09:03
Joined
Jan 20, 2009
Messages
12,856
Single and Double are the types for real numbers. They can handle very large and very small numbers but they are not always quite exact due to the vagaries of holding a base ten decimal in a base two system.

Decimal is a precision format held as an integer with a scaling factor. It is used where precision results must be had from fractional numbers. Currency is a type of decimal with the scaling factor fixed at four decimal places so it is precise to this level. It is often used for such calculations. Decimal is a used if further precision is required,

To use Decimal in VBA one must Dim as Variant then convert the assigned value to Decimal with the CDec() function.
 

Users who are viewing this thread

Top Bottom