Click here to Skip to main content
15,126,367 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Updated 4-Jan-12 1:46am
Nicholas Butler 4-Jan-12 7:00am
Convert.ToDouble( string ) just calls Double.Parse. There is also an overload that takes an IFormatProvider.


Remove comma and try on that convert.ToDouble
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);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900