I have a phone number formatted as an easy to read phone number, i.e., (123) 123-4567
However, when I want to use that phone number in code, I need to p
2147483647 is INT_MAX which is returned on overflow. How large is your phone number, will it fit into an int
? Maybe you should use longLongValue
?
As CRD has already explained, you're trying to convert that string to a type that's too small to hold the value, and you're getting back the maximum possible value for that type.
Your real problem is deeper, however. A phone "number" isn't really a number. It doesn't represent a quantity. You would never perform arithmetic on one. It's actually a string of digits, and you should handle it that way. Don't convert it; just operate on the string.
See also What's the right way to represent phone numbers?