Solved

# Simple VB Question

Posted on 2003-10-29

I am not a VB expert and I am trying to make a simple function that will count the number of decimal places there is in a number. This is what I've done:

Public Function countDecimalPlaces(number As Double) As Integer

Do While number > Math.Round(number)

number = number * 10

countDecimalPlaces = countDecimalPlaces + 1

Loop

End Function

The problem is that it only works for up to 5 digits because in the comparison line for the loop (Do While number > Math.Round(number)), the Math.Round(number) part makes an integer, thus the the 5 digits the function will work until. I have tried a few other things for the right side of the inequation (ie: multiplying and dividing by powers of 10, using Int(number), etc.) but got the same results.

I can't seem to cast the right side of the inequation into a double properly.

Your help is much appreciated.