(google groups hates me)
Hey all,
I ran into this problem (subject) when adding numbers
using "floatFromMixedNumberString". Turns out it was parsing out empty
strings (@"") and considering them as 0.0 as a float, which led to a
divide-by-zero.
Long story short, I converted this:
NSArray *parts = [str componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" /"]];
to this:
NSArray *tempParts = [str componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" /"]];
NSMutableArray *parts = [NSMutableArray arrayWithArray:tempParts];
int counter = ([parts count] - 1);
float value;
while (counter > 0) {
value = [[parts objectAtIndex:counter] floatValue];
NSLog(@"%f", [[parts objectAtIndex:counter] floatValue]);
if (value < 1) {
[parts removeObjectAtIndex:counter];
}
counter--;
}
//NSLog(@"parts:%@", parts);
to check for zeros before performing arithmetic (it's a hack, I know).
Just in case someone else gets (null) strips of bacon too...
-ben