I am loath to reinvent this bicycle and am hoping to be shown the tried and true way to handle this problem.
I'm collecting numeric values from users via some String interface (text input for instance).
I want to make sure that regardless of what type of memory space I'm using for collecting this info, I don't allow the user to enter a number that exceeds this value.
My intuition tells me that the only way to do this is to actually measure the string length of the max value... such as...
if( (userInput + "").length() > (Integer.MAX_VALUE + "").length()){
//user has entered too many digits for an Integer to hold.
}
But this looks ugly to me and I'm guessing there's a cleaner way to handle this.