Lumart Lumart - 5 months ago 11
Vb.net Question

Decimal places in a number on vb.net

How do I check how many decimal places does a number have in VB.net?

For example: Inside a loop I have an if statement and on that statement I want to check if a number has 4 decimal places (8.9659)

Answer
Dim numberAsString As String = myNumber.ToString()
Dim indexOfDecimalPoint As Integer = numberAsString.IndexOf(".")
Dim numberOfDecimals As Integer = _
    numberAsString.Substring(indexOfDecimalPoint + 1).Length
Comments