I have an interesting situatin to solve, its more like a quiz :)
I have to recreate a simple calculator and I have two buttons with up/down on it. The function of this two buttons are simpe, they take the current value and it sums 1 or take 1. So I manage to create a small function that convert the value into a string and in case of 34.1, I create the new value of 0.1 to add or subtract.
- (float)findFloatValueToAdd:(NSString *)aString
{
NSMutableString *val = [NSMutableString stringWithCapacity:aString.length];
for (int i = 0; i < aString.length; i++)
[val appendFormat:@"0"];
if ([aString rangeOfString:@"."].location != NSNotFound)
[val replaceCharactersInRange:NSMakeRange([aString rangeOfString:@"."].location, 1)
withString:@"."];
[val replaceCharactersInRange:NSMakeRange(aString.length-1, 1)
withString:@"1"];
return [val floatValue];
}
The main problem is when I have lot of decimals like 23.1234212. If I have to go up it jumps direct to 23.12342, down the same. If i continue to go down from 23.12342, it goes to 23.12341 > 23.1234 but then it goes to 23.1233>23.1232>23.1231...
So, how can I truly solve this problem?
thanks guys!