Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.2 kB
1
Indexable
Never
Private Function Get_number(Numb As String) As Double
    Dim i As Integer
    Dim dcn As String
    Dim numbr As Double
    Dim Neg As String
    
    dcn = "0"
    Neg = "0"
    
    For i = 1 To Len(Numb)
        If IsNumeric(Mid(Numb, i, 1)) Or Mid(Numb, i, 1) = "." Or Mid(Numb, i, 1) = "-" Or Mid(Numb, i, 1) = "," Then
            If dcn <> "0" Then
                dcn = dcn & "0"
            End If
            If Mid(Numb, i, 1) = "." Then
                dcn = "1"
            End If
            If Mid(Numb, i, 1) = "-" Then
                Neg = "1"
            End If
            If Mid(Numb, i, 1) <> "," Then
                numbr = numbr & Mid(Numb, i, 1)
            End If
        End If
    Next
    
    If dcn > 1 Then
        ' Check if decimal part has more than 2 digits
        Dim decimalDigits As Integer
        decimalDigits = Len(Mid(numbr, InStr(numbr, ".") + 1))
        
        If decimalDigits > 2 Then
            numbr = Round(numbr, 2)
        End If
        
        Get_number = Val(numbr) / Val(dcn)
    Else
        Get_number = Val(numbr)
    End If
    
    If Neg <> "0" Then
        Get_number = Get_number * -1
    End If
    
    ' Return
End Function
Leave a Comment