开发者

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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜