• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 494
  • Last Modified:

Convert.ToInt32("300.00") Giving error

Hi

I have a statement

Convert.ToInt32("300.00")

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

Thanks

I
0
ianinspain
Asked:
ianinspain
  • 4
  • 4
1 Solution
 
ddunleaCommented:
Hi ianinspain,

Convert.ToInt32(Convert.ToDouble("300.00"));

Regards
0
 
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..
0
 
ianinspainAuthor Commented:
I also tried
Convert.ToInt32(Convert.ToDouble("300.00"));

same problem
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ddunleaCommented:
ianinspain,

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.
0
 
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
0
 
ddunleaCommented:
ianinspain,

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.
0
 
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

Ian
0
 
ddunleaCommented:
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now