Is there an efficient method in VB to check if a string can be converted to a double?
I'm currently doing this by trying to convert the string to a double and then seeing if it throws an exception. But this seems to be slowing down my application.
Try
' if number then format it.
current = CDbl(x)
current = Math.Round(current, d)
Return current
Catch ex As System.InvalidCastException
' item is not a number, do not format... leave as a string
Return x
End Try
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…