ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Rounding a formula in code (https://www.excelbanter.com/excel-programming/441496-rounding-formula-code.html)

ordnance1[_2_]

Rounding a formula in code
 
How can I round this out to the 4th digit?

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


Joe User[_2_]

Rounding a formula in code
 
"ordnance1" 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.



All times are GMT +1. The time now is 11:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com