double to int and comparison
I have a textfield and want to get the value stored as double and also compare whether it is between 2 and 20
dou开发者_如何学运维ble numOfYears = [[numOfYearsFld text] doubleValue];
Please let me know if the code above is correct and how can i compare/check between 2 and 20, since it is double ?
Yes, while your text field contains valid number your code to get its double value is OK (if field does not contain valid number your code will return 0).
Checking if your value is between 2 and 20 does not differ from what you would do in case you had integer (or any other plain number type):
if (numOfYears >= 2 && numOfYears <=20){
// check passed
}
精彩评论