Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
712 B
1
Indexable
Never
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
Leave a Comment