Untitled

 avatar
unknown
plain_text
a year ago
712 B
5
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