Hi all:
I am trying to parse numeric input a user provides on a web site.
I am having a problem with dollar amounts. The following command results in an OverflowException:
int.Parse("77,500.50", NumberStyles.Currency, CultureInfo.CurrentCulture)
but all of the following commands do not:
int.Parse("77,500.00", NumberStyles.Currency, CultureInfo.CurrentCulture)
int.Parse("77,50050", NumberStyles.Currency, CultureInfo.CurrentCulture)
decimal.Parse("77,500.50", NumberStyles.Currency, CultureInfo.CurrentCulture)
Note: the current culture is "en-US".
I understand that the integer can't hold the decimal portion of the number, but according to the documentation (.NET 2.0), an OverflowException is thrown if
"s represents a number less than MinValue or greater than MaxValue"
The resulting number is obviously not too large or small to fit in an integer.
I can work around this, but I think that the Framework should handle this situation better.
Thanks,
SA.