Rounding

wllsth

Registered User.
Local time
Today, 14:34
Joined
Sep 17, 2008
Messages
81
I have a problem with rounding.

I wish the field TxtCost to contain the rounded up result (2 Decimal Places) of Billable Hours * TxtRate. It appears correctly on the screen but it stores the unrounded figure in the table.

Here's my VBA code.

Private Sub Billable_Hours_AfterUpdate()
Me.TxtCost = Me![Billable Hours] * Me![TxtRate]
End Sub
 
Wrap your calculation in the Round() function (more info in Help).
 
Not quite there it seems to round down NOT up, here's my code

Me.TxtCost = Round(Me![Billable Hours] * Me![TxtRate], 2)

Billable Hours(1.5) * TxtRate(10.39) gives 15.58 instead of 15.59
 
Thanks Paul, i was trying to figure away round this myself. Now I can look at this link. Learn something new every day.
 
I found the following bit of code on the following website
http://support.microsoft.com/kb/196652/EN-US/

Function AsymArith(ByVal X As Double, _
Optional ByVal Factor As Double = 1) As Double
AsymArith = Int(X * Factor + 0.5) / Factor
End Function

When I use it as follows :-
Private Sub Billable_Hours_AfterUpdate()
Me.TxtCost = Me![Billable Hours] * Me![TxtRate]
Me.TxtCost = AsymArith(Me.TxtCost, 100)
End Sub

I get the following result :-
Billable Hours(1.5) * TxtRate(4.09) = 6.135
Rounded to 6.13 NOT 6.14

I thought AsymArith would always round .5 upwards
 

Users who are viewing this thread

Back
Top Bottom