Only on my machine this happens. Basically if i run the following all is as expected:
double d = 500.22;
int i = (int)d;
Console.WriteLine(i.ToString());
Output is 500.
However if i put a breakpoint on the first line and step through, i always reverts to zero and the output is 0.
I've tested this on other machines and I cannot replicate, I've even reinstalled VS2010 and it still happens. So I'm thinking it must be some sort of environment setting that I have on my system, but I cannot figure out what.
Anyone else had this issue and how do I get rid of it.
Cheers.
EDIT: It appears that the issue is just with the 2nd line. If I put a break point on the 1st line and then just F5 over it, then it's all ok. But if I step into/over the 2nd line, the casting doesn't appear to work and i stays at 0.
I also tried setting i to 1 first and then seeing if the cast works, but it changes i back to 0 and removes my initial value of 1.
Here's a screenshot:
Do you have all the latest .NET Framework service patches? There are some even for the 4.0 framework, though I haven't heard of anything like this yet.
* Edit *
Regarding my other suggestions, casting to an int truncates, and Convert.ToInt32 rounds, so Convert.ToInt32 is what you generally want anyway (especially if it's working).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With