Manufacturing Information Solutions Forum Index Manufacturing Information Solutions
Your Place for Support and Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Creating a custom round function

 
Post new topic   Reply to topic    Manufacturing Information Solutions Forum Index -> Microsoft Access
View previous topic :: View next topic  
Author Message
BIGmiralli
Frequent Poster


Joined: 17 Apr 2007
Posts: 38
Location: Boston, Massachusetts

PostPosted: Fri May 23, 2008 8:53 am    Post subject: Creating a custom round function Reply with quote

Question: In Access, I have an Overtime form for the employees. My problem is that while calculating the value, I need the following rules to apply:

If the fraction portion of the number is below 0.5, then I want to round the number down.
If the fraction portion is greater than or equal to 0.5, then the fraction should be 0.5.

For example, a value of 6.7 hours should display as 6.5.




Answer: To accomplish this, you need to create a custom function.

You'll need to open your Access database and create a new module.

Then paste into the new module the following function:

Code:
Function CustomRound(pValue As Double) As Double

   Dim LWhole As Long
   Dim LFraction As Double

   'Retrieve integer part of the number
   LWhole = Int(pValue)

   'Retrieve the fraction part of the number
   LFraction = pValue - LWhole

   If LFraction < 0.5 Then
      CustomRound = LWhole
   Else
      CustomRound = LWhole + 0.5
   End If

End Function




Now, when you want to round your values, you can use the round function as follows:

CustomRound (6.7) would return 6.5
CustomRound (6.5) would return 6.5
CustomRound (6.49) would return 6.0
________
GROW MEDICAL MARIJUANA
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Manufacturing Information Solutions Forum Index -> Microsoft Access All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group