Wrong result from IsNumeric() in VB.NET

扶醉桌前 提交于 2019-12-02 11:16:12

问题


I have a function in VB.NET that loops through values and attempts to convert it to a decimal if IsNumeric is True,

Dim Value As String

If IsNumeric(Value) = True Then
    Rate = CType(Value, Decimal)  <--- bombing here
End If

I've found that when the function receives the value 603E43 IsNumeric evaluates to True for some reason and then bombs on the conversion. Why would IsNumeric be true in this case?


回答1:


See http://support.microsoft.com/kb/329488

IsNumeric returns true if it can be converted to a double which is true for 603E43 The value is however larger than what a decimal can hold

You could use the Decimal.TryParse funcion as a working alternative. See http://msdn.microsoft.com/en-us/library/9zbda557.aspx



来源:https://stackoverflow.com/questions/6770117/wrong-result-from-isnumeric-in-vb-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!