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

Result = Me.GRP_MAX_YTH_NBR \ Me.GRP_MAX_LDR_NBR

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?

Thanks,
Bob C.
Bob CollisonSystem ArchitectAsked:
Who is Participating?

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

x
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

1

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
https://support.office.com/en-us/article/Table-of-operators-E1BC04D5-8B76-429F-A252-E9223117D6BD


use / for regular division

here are some examples using / and \ so you can see the difference:    
?3/4
 0.75 

?3\4
 0 

? 3 \ 5
 0 
? 7 \ 5
 1 

?3 / 5
 0.6 

? 7 / 5
 1.4 

Open in new window


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

Thanks for the solution / comments.

Bob C.
0
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
you're welcome, Bob ~ happy to help
0
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.