By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,830 Members | 682 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,830 IT Pros & Developers. It's quick & easy.

Difference in round off

P: 232
Expand|Select|Wrap|Line Numbers
  1. Function da(BP, DP)
  2. da = Round(139 / 100 * (BP + DP))
  3. End Function
In Function da returns to be 7297 but in the immediate window which is correct ?ROUND(139/100*(3500+1750))

I checked through debugging too that in the function also bp=3500 and dp=1750

I can't get the reason behind it.
Kindly Help
Thanks in advance

May 30 '12 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 100+
P: 2,321
Your problem arises from lack of the definiton of your variable types. You have not informed access what to expect as input, whether the input is apples or oranges or numbers.

When access finds a undeclared variable it assumes it to be a Variant. Your function statement is equivalent to:
Expand|Select|Wrap|Line Numbers
  1. Public Function da2(bp As Variant, dp As Variant) As variant
  2.    da2 = Round(139 / 100 * (bp + dp))
  3. End Function
Which also yields 7297.

A correct functional statement could look like:
Expand|Select|Wrap|Line Numbers
  1. Public Function da3(bp As Double, dp As Double) As Double
  2.    da3 = Round(139 / 100 * (bp + dp))
  3. End Function
which returns 7298.
May 30 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.