Untitled
unknown
plain_text
2 years ago
712 B
8
Indexable
Function KeepFirstTwoDigitsAfterDecimal(ByVal number As Double) As String
Dim strNumber As String
Dim decimalPosition As Integer
' Convert number to string
strNumber = Format$(number, "0.00")
' Find the position of the decimal point
decimalPosition = InStr(1, strNumber, ".")
' Keep only the first two characters after the decimal point
If decimalPosition > 0 And Len(strNumber) >= decimalPosition + 2 Then
KeepFirstTwoDigitsAfterDecimal = Left(strNumber, decimalPosition + 2)
Else
' If there are less than two digits after the decimal point, return the original number
KeepFirstTwoDigitsAfterDecimal = strNumber
End If
End Function
Editor is loading...
Leave a Comment