Difference in round off

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kkshansid
    New Member
    • Oct 2008
    • 232

    Difference in round off

    Code:
    Function da(BP, DP)
    da = Round(139 / 100 * (BP + DP))
    End Function
    In Function da returns to be 7297 but in the immediate window which is correct ?ROUND(139/100*(3500+1750) )
    7298

    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

    ACCESS 2007
    Last edited by Frinavale; May 30 '12, 01:26 PM. Reason: Formatted the post: removed all caps. Writing a post in all caps is the internet equivalent of shouting, and is considered rude by alot of internet forums.
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    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:
    Code:
    Public Function da2(bp As Variant, dp As Variant) As variant
       da2 = Round(139 / 100 * (bp + dp))
    End Function
    Which also yields 7297.

    A correct functional statement could look like:
    Code:
    Public Function da3(bp As Double, dp As Double) As Double
       da3 = Round(139 / 100 * (bp + dp))
    End Function
    which returns 7298.
    Last edited by Frinavale; May 30 '12, 01:25 PM. Reason: Removed all caps from original post. Edited your post to remove mention of the problem.

    Comment

    Working...