elHollandes
Programmer
Hi all,
Here´s a function to find the number of decimals from a number. I don´t like it, but can´t find a better way. The function could be a lot faster if I dont have to convert to a string or at least don´t have to searge for points and comma´s. Since I use this function many times, speed is important. Maybe if I only knew how VB stores a double... Anyone has somthing better?
Thanks, El Holandais
START LISTING
Public Function iDecimals(ByVal iNumber As Double) As Integer
Dim sNumber As String
sNumber = Format(iNumber)
'convert to string
If InStr(sNumber, ".") > 0 Then
'has decimal point
iDecimals = Len(sNumber) - InStr(sNumber, ".")
'numbers after point
ElseIf InStr(sNumber, ",") > 0 Then
'has decimal comma
iDecimals = Len(sNumber) - InStr(sNumber, ",")
'numbers after comma
Else
'has no point or comma
iDecimals = 0
'no decimals
End If
End Function
END LISTING
Here´s a function to find the number of decimals from a number. I don´t like it, but can´t find a better way. The function could be a lot faster if I dont have to convert to a string or at least don´t have to searge for points and comma´s. Since I use this function many times, speed is important. Maybe if I only knew how VB stores a double... Anyone has somthing better?
Thanks, El Holandais
START LISTING
Public Function iDecimals(ByVal iNumber As Double) As Integer
Dim sNumber As String
sNumber = Format(iNumber)
'convert to string
If InStr(sNumber, ".") > 0 Then
'has decimal point
iDecimals = Len(sNumber) - InStr(sNumber, ".")
'numbers after point
ElseIf InStr(sNumber, ",") > 0 Then
'has decimal comma
iDecimals = Len(sNumber) - InStr(sNumber, ",")
'numbers after comma
Else
'has no point or comma
iDecimals = 0
'no decimals
End If
End Function
END LISTING