本文介绍了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

推荐答案


string data = "8,000";
double d = double.Parse(data, NumberStyles.AllowThousands);


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收到数字错误.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 00:19