Comparing NSNumbers in Objective C
I assume number1 and number2 are pointers to objects. The < sign is comparing the pointers. You need to compare the actual floatValue or doubleValue if ([number1 doubleValue] < [number2 doubleValue]) ….
I assume number1 and number2 are pointers to objects. The < sign is comparing the pointers. You need to compare the actual floatValue or doubleValue if ([number1 doubleValue] < [number2 doubleValue]) ….
There is not really a better way, but you really should not be doing this if you can avoid it. NSNumber exists as a wrapper to scalar numbers so you can store them in collections and pass them polymorphically with other NSObjects. They are not really used to store numbers in actual math. If you … Read more
Have a look at the documentation. Use the intValue method: NSNumber *number = [dict objectForKey:@”integer”]; int intValue = [number intValue];
Try: NSString *myString = [NSNumber stringValue];
Use an NSNumberFormatter: NSNumberFormatter *f = [[NSNumberFormatter alloc] init]; f.numberStyle = NSNumberFormatterDecimalStyle; NSNumber *myNumber = [f numberFromString:@”42″]; If the string is not a valid number, then myNumber will be nil. If it is a valid number, then you now have all of the NSNumber goodness to figure out what kind of number it actually is.