I need to create a way to round a specific variable(metertemp and provertemp) to be rounded to either xx.x0 or xx.x5 all other variables can use the current code below.
My current code is:
Code:
Function MathRound(Numeral As Variant, Optional Decimals As Integer, Optional Keep_Trailing_Zeroes As Boolean) As Variant
'Used instead of round funciton to avoid bankers rounding (format does arithmetic rounding)
Dim Xloop As Integer
Dim PlaceString As String
Dim ZeroString As String
If Numeral = 0 Then
MathRound = 0
Exit Function
End If
If Decimals > 0 Then
'not whole
For Xloop = 1 To Decimals
'build custom formatting string
PlaceString = PlaceString + "#"
ZeroString = ZeroString + "0"
Next Xloop
If Keep_Trailing_Zeroes = True Then 'keep trailing zeroes for later use
MathRound = Format(Numeral, "##############." & ZeroString)
Else
MathRound = Format(Numeral, "##############." & PlaceString)
End If
Else
'round whole
MathRound = Format(Numeral, "##############")
End If
End Function
Please help
Thank you