iOS 4+ when I pass the nil value to my NSNumberFormatter, I want the nil character (NSString *) to be set at the end. It works for the null character, but not for the nil character. I tried many different configuration settings such as behavior, grouping, etc.
fmtr = [[NSNumberFormatter alloc] init]; [fmtr setNumberStyle:NSNumberFormatterDecimalStyle]; [fmtr setFormatterBehavior:NSNumberFormatterBehaviorDefault]; [fmtr setUsesGroupingSeparator:NO]; [fmtr setNilSymbol:@"###"]; [fmtr setZeroSymbol:@"0000"]; NSLog(@"[fmtr nilSymbol]=>>%@<<", [fmtr nilSymbol]); NSLog(@"[fmtr stringFromNumber:nil]=>>%@<< this should be '###", [fmtr stringFromNumber:nil] ); NSLog(@"[fmtr stringFromNumber:0]=>>%@<<", [fmtr stringFromNumber:[NSNumber numberWithInt:0]] ); NSLog(@"[fmtr stringFromNumber:null]=>>%@<<", [fmtr stringFromNumber:NULL] ); NSLog(@"[fmtr numberFromString:nil]=%@", [fmtr numberFromString:nil] ); NSLog(@"[fmtr numberFromString:@\"0\"]=%@", [fmtr numberFromString:@"0"] ); NSLog(@"[fmtr numberFromString:NULL]=%@", [fmtr numberFromString:NULL] );
Here is the test result:
[fmtr nilSymbol] = β ### <<
[fmtr stringFromNumber: nil] = β (null) <<it should be "###
[fmtr stringFromNumber: 0] = β 0000 <
[fmtr stringFromNumber: null] = β (null) <<
[fmtr numberFromString: nil] = (null)
[fmtr numberFromString: @ "0"] = 0
[fmtr numberFromString: NULL] = (null)
source share