No exception is thrown, function just halts at this statement:
int productQuantity = Convert.ToInt32("1.00");
and returns.
What am I doing wrong to convert this float to Int32?
Note: I am running in a BackgroundWorkerThread.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
An exception is being thrown in this case it’s just not being surfaced in the debugger. This string is not in a format that is convertible to an
Int32type and hence throws and exception. You can verify this by wrapping it in a try/catch block if the IDE isn’t cooperating.The best approach here is probably to convert the string to a
doubleand then manually cast it down to anint. This does open the door for data loss due to precision differences. But given your input is in a float style format this is unavoidable if you want the final product to be anint