Reputation: 11
I am getting below error while i am converting integer value string to short from text box in .net.
Value was either too large or too small for an Int16. How can i convert ZIP code and Phone number values from text boxes? Please help me...
Upvotes: 1
Views: 10736
Reputation: 31
Agree with keeping it as a string: converting zip codes/phone numbers to a number will not bring nothing useful (who would like to sum phone numbers?)
An on the other side: phone numbers does have leading zeros (important) what would be lost by conversion to a number. Canadian zip codes contain also alphabet characters.
Upvotes: 3
Reputation: 55937
Expanding on @Marc and @jimmy's points:
Zip codes and phone numbers are not numbers, you don't do arithmetic with them. So just treat them as Strings. In some countries the equivalent of a Zip code is a string like this: "PA6 0UN", if you treat your zip/postal code as a string then you can cope with such "foreign" constructs.
It might be true that there is a space-saving benefit in representing a phone number as a numeric quantity, but the saving is likely to be tiny in comparison with all the rest of the data you are keeping, and processing costs of formatting and parsing will be incurred.
Upvotes: 3
Reputation: 1063619
A 16-bit signed integer has a very small range (-32768 to 32767). In all honesty, you should not be attempting to parse them as such - just store them as string
.
Upvotes: 9