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

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

GillIT

Thread Starter
Joined
Jul 17, 2003
Messages
53
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

Joined
Feb 19, 1999
Messages
260
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?
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top