将字符串转换为双VB [英] Convert String to Double - VB

查看:122
本文介绍了将字符串转换为双VB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VB中有一个有效的方法来检查一个字符串是否可以转换为双精度?

Is there an efficient method in VB to check if a string can be converted to a double?

我正在尝试将字符串转换为一个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


推荐答案

如果您使用的是.NET 1.1 / 2.0 / 3.0 / 3.5 / 4.0 / 4.5,请尝试查看Double.TryParse()

Try looking at Double.TryParse() if you are using .NET 1.1/2.0/3.0/3.5/4.0/4.5

这篇关于将字符串转换为双VB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆