
Getting the number of decimal places from a number
Good point about the international decimal separator.
The expression
Format$(0, ".")
will also return the decimal separator. (And for those non-believers out
there, yes, this *does* work for international settings -- try it before
responding that it doesn't.)
Modifying my original code yields:
NumAsStr = CStr(YourNumber)
Sep = Format$(0, ".")
If NumAsStr Like "*" & Sep & "*" Then
DecimalPlaces = Len(NumAsStr) - InStr(NumAsStr, Sep)
Else
DecimalPlaces = 0
End If
Rick
Quote:
> For more international flare, you might want to check what the decimal
> separator is, and test for that:
> Private Function DecimalPlaces(Num#) As Long
> Dim tmp$, sep$
> sep = Mid$(CStr(1 / 2), 2, 1)
> tmp = CStr(Num)
> DecimalPlaces = Len(Mid$(tmp, InStr(tmp, sep) + 1))
> End Function
> LFS
> > The number of digits after the decimal point can be found like this:
> > NumAsStr = CStr(YourNumber)
> > If NumAsStr Like "*.*" Then
> > DecimalPlaces = Len(NumAsStr) - InStr(NumAsStr, ".")
> > Else
> > DecimalPlaces = 0
> > End If
> > Rick
> > "wendy gatanis" wrote
> > > Is there a function that will return the number of decimal places in
a
> > > number?
> > > --
> > > Wendy Gatanis, Product Manager