Click here to Skip to main content
15,867,686 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
Posted
Updated 4-Jan-12 0:46am
v2
Comments
Nicholas Butler 4-Jan-12 7:00am    
Convert.ToDouble( string ) just calls Double.Parse. There is also an overload that takes an IFormatProvider.

Hi,

{8888)
Remove comma and try on that convert.ToDouble
 
Share this answer
 
Use Parse instead:
C#
string data = "8,000";
double d = double.Parse(data, NumberStyles.AllowThousands);
 
Share this answer
 
Can Try this,

C#
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);
        }
 
Share this answer
 

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