Rounding a formula in code

  • Follow


How can I round this out to the 4th digit?

TextBox13.Value = (TimeValue(TextBox12.Value) - TimeValue(TextBox11.Value)) 
* 24 

0
Reply ordnance1 4/9/2010 4:33:52 PM

"ordnance1" <ordnance1@comcast.net> wrote:
> How can I round this out to the 4th digit?
> TextBox13.Value = (TimeValue(TextBox12.Value)
> - TimeValue(TextBox11.Value)) * 24

TextBox13.Value = Round((TimeValue(TextBox12.Value) _
- TimeValue(TextBox11.Value)) * 24, 4)

or

TextBox13.Value = WorksheetFunction.Round((TimeValue(TextBox12.Value) _
- TimeValue(TextBox11.Value)) * 24, 4)

The difference is that VBA Round does "banker's rounding".  Compare 
Round(2.5,0) and WorksheetFunction.Round(2.5,0).

PS:  I will try to send email to the address that you used above.  If you do 
not see my message, please check this thread again for an off-topic 
follow-up. 

0
Reply Joe 4/9/2010 5:00:06 PM


1 Replies
248 Views

(page loaded in 0.051 seconds)


Reply: