I have a double value that I would like to convert to Int32. How can I check before conversion if it can be converted?
Sometimes the value is undefined, and conversion to Int32 raises an OverflowException.
I already tried to check it like this:
double value = getSomeValue();
if (value == Double.NAN) {
value =0;
}
int v = Convert.ToInt32(value);
But this does not apply to all cases.
anon
source
share