covert.todouble收到数字错误. [英] covert.todouble is getting error for a number.

查看:72
本文介绍了covert.todouble收到数字错误.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当iam使用
进行类型转换时,我会得到一个这样的数字(8,888)
convert.ToDouble由于输入字符串的格式不正确,我引发了期望.

我的电话号码显示应该只像上面那样

iam getting a number (8,888) like this when iam doing type casting with

convert.ToDouble it is throwing expection as input string was not in correct format how can i validate

my number display should be like that only as above

推荐答案



{8888)
删除逗号并尝试进行转换.ToDouble
Hi,

{8888)
Remove comma and try on that convert.ToDouble


改为使用Parse:
Use Parse instead:
string data = "8,000";
double d = double.Parse(data, NumberStyles.AllowThousands);


可以尝试一下,

Can Try this,

string s = "123,456.78";
        double value;
        bool flag = double.TryParse(s, NumberStyles.Currency, CultureInfo.CurrentCulture.NumberFormat, out value);
        if (flag)
        {
            Console.WriteLine("Entered Amount is :" + value);
        }


这篇关于covert.todouble收到数字错误.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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