code:
-(IBAction)addRounds{
NSString *addText = [NSString stringWithFormat:@"%@", self.roundsF.text];
NSString *totalText = [NSString stringWithFormat:@"%@", self.totalRoundsF.text];
int value = [totalText intValue] - [addText intValue];
NSNumber *val = [NSNumber numberWithInt:value];
NSString *final = [NSString stringWithFormat:@"%@", val.stringValue];
self.totalRoundsF.text = final;
}
The above code works perfectly, however when it displays the data into the textfield, it will show something like : -10 the number 10 is correct, i just dont want a - sign. Any help is greatly appreciated, Thank you very much!
You do not want negative value at all? In that case use
absabsolute value. This will always give you positive values.Depending on the type of your variable, one of
abs(int),labs(long),llabs(long long),imaxabs(intmax_t),fabsf(float),fabs(double), orfabsl(long double).These functions are part of the C library and are present in Objective-C library as well. You might have to import
math.hto use them.so in your case it would be
abs(val); //will give +10