Reputation: 80
I want to check the number is in range of 1 to 100, 100 to 200 and so on but without using if conditions. if it is in range of 1 to 100 return 100.
Upvotes: 1
Views: 111
Reputation: 109
you can use the following function
-(int)getOutput:(int)input{
int temp = (input+99)/100; //(eg :- temp=(99+99)/100=1;
int output=temp*100 //(eg :- 1*100 =100);
return output;
}
Upvotes: 0
Reputation: 1643
- (int)getRange:(int)value
{
int range = value / 100;
range = (range * 100) + ((value % 100) > 0 ? 100 : 0);
return range;
}
Try this hope it ll help you..
Upvotes: 0
Reputation: 775
/* we need to get 700 in result */
NSInteger myNumber = 619;
/* outputNumber will give 700 in result */
NSInteger outputNumber = (NSInteger)(ceil(myNumber/100) * 100);
Upvotes: 0
Reputation: 24714
If the type is int
For 1-100,101-200,
int x = 99;
x = ((x-1)/100 + 1)*100;
For 1-50,51-100
int x= 51;
x = ((x-1)/50 + 1)*50;
Upvotes: 7