Convert.ToInt32("300.00") Giving error


I have a statement


But it gives an error, it is obviosuly the .00 because if i remove that it works...

Is there anyway to force it to ??   The "300.00" actually comes from a string. Its a decimal number but in string format


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi ianinspain,


ianinspainAuthor Commented:
Thanks for the info but still gives a problem..

? Convert.ToInt32(Convert.ToDecimal("300.00"));
error: managed EE does not understand expression's syntax

Tried above in a command window when debuging..
ianinspainAuthor Commented:
I also tried

same problem
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.


The exact code I have is:

    int i = System.Convert.ToInt32(System.Convert.ToDouble("300.00"));

And this works.

What do you mean when you say you "tried it in a command window"? You can't just type it into the watch window of the debugger - you have to put it as a line of code in your program.
ianinspainAuthor Commented:
Hi ddunlea,

Yep you are right! It seems to work ... this is my actual line

if (Convert.ToInt32(Convert.ToDouble(priceFromDropDownList.SelectedValue)) != 0) // Ensure they chose something

But how do I find out what this is going to produce before i run it, I have a break point on this line so if I put my curser over priceFromDropDownList.SelectedValue   then i can see 2000000.00 ... but if i put my cursor over anything else it displays <overloaded>..

I did goto a command window while debugging, but I thought I could put

? Convert.ToInt32(Convert.ToDouble(priceFromDropDownList.SelectedValue))

but it displays 0, which isn't correct.

Sorry I come from a VB background and used to be able to do that, test variables and various things in the command window before continueing

Any ideas?

Thanks .. though it seems to have worked

The easiest way is to break it up as follows:

string str = priceFromDropDownList.SelectedValue.ToString();
double d = Convert.ToDouble(str);
int i = Convert.ToInt32(d);

if(i != 0){

Then you can watch each intermediate variable.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ianinspainAuthor Commented:
ok ... thanks... wow so there isn't anyway to do what i used to do in VB

What a knockback <grin>...

It used to be great to drop to the command line window and hold your cursor over the end statement and find out exactly what it was..

What a shame

Thanks alot

Hi ianinspain,

Sometimes you can. It depends. You can examine variables and properties, but you can usually only examine simple funtion results.

Hope that helps.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.