# .NET C#- String to Decimal Conversion - Format exception



## GillIT (Jul 17, 2003)

Hey everyone,

The code is supposed to take a webservice output which is a string and convert it to a currency string. The only way I learned to get it to work is to convert it to a decimal then convert it back to a string as currency string. This worked fine with all the other webservices, except for just this one. For some reason it doesn't like to convert the string to a decimal. It works fine as long as I do not convert it but then it leaves a lot of following significant digits that I do not want. I have tried copy/pasting the solution directing into the decimal conversion and works fine. I am at a lost what the problem is. I can store it in a string, but cannot convert it to decimal.



Here is the error I received:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.FormatException: Input string was not in a correct format.

Here is my code:
string strTest2 = tk.webserviceX("aaa", "bbb");
decimal x;
string y;
strTest2 = "00123.321";
strTest2 = tk.webserviceX("aaa", "bbb");
x = Convert.ToDecimal(strTest2);
y = x.ToString("C");
lblError1.Text = y;

The error is line:
x = Convert.ToDecimal(strTest2);



Thanks.


----------



## Guy (Feb 19, 1999)

I would love to help but I am unfamiliar with tk.webserviceX("aaa", "bbb"); and I cannot find it in the docs.

Have you tried debugging and stepping through the program to make sure that all values are as expected?


----------



## Gibble (Oct 10, 2001)

what is the value of strTest2 immediately before the line "x = ..."


----------

