Acess 2010 VBA Display Fraction As Decimal

Hi Experts,

I have the following calculation in VBA.

Dim Me.GRP_MAX_YTH_NBR As Integer.  Value = 3
Dim Me.GRP_MAX_LDR_NBR As Integer,  Value = 4
Dim Result As Long


The above calculation returns Result = 0

How do I get it to return a result of 0.75 which is the decimal equivalent the fraction 3/4?

Bob C.
Bob CollisonSystem ArchitectAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
Change the declaration of Result from Long (integer) to Double.
Dim Result As Double 

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
hi Bob,

adding onto Norie's comment about changing data type ... (long integer cannot  store a decimal place, therefore rounding is done on factors and result is truncated) ...

Actually, though, there are two things wrong:

1. Dim Result As Long: whole numbers cannot have decimal places. Therefore, 0.75 cannot be written for the result.
2. Result = factor1 \ factor2  : formula is truncating decimal places by using \
   therefore Result does not even have a chance to get rounded (due to Dim as Long); it is already truncated

/ and \ are different operators for division

Table of operators

use / for regular division

here are some examples using / and \ so you can see the difference:    


? 3 \ 5
? 7 \ 5

?3 / 5

? 7 / 5

Open in new window

have an awesome day,
Bob CollisonSystem ArchitectAuthor Commented:
Hi Experts,

Thanks for the solution / comments.

Bob C.
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
you're welcome, Bob ~ happy to help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.