本文介绍了VB.NET中IsNumeric()的错误结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VB.NET中有一个函数,它循环遍历值,如果IsNumeric为True,则尝试将其转换为十进制.

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

我发现,由于某种原因,当函数接收到值603E43 IsNumeric时,其值为True,然后在转换时产生炸弹.为什么在这种情况下IsNumeric是正确的?

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?

推荐答案

请参见 http://support.microsoft .com/kb/329488

IsNumeric转换为 double ,则返回true,这对于603E43是正确的但是,该值大于小数位数可以容纳的值

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

您可以使用Decimal.TryParse函数作为替代方法.看 http://msdn.microsoft.com/en-us/library/9zbda557.aspx

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

这篇关于VB.NET中IsNumeric()的错误结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 23:08