【发布时间】:2011-04-26 22:19:38
【问题描述】:
iOS 4+;当我将 nil 值传递给我的 NSNumberFormatter 时,我想要设置的 nil 符号 (NSString *) 作为回报。它适用于“零”符号,但不适用于零符号。我尝试了许多不同的配置设置,例如行为、分组等。
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] );
这是测试的输出:
[fmtr nilSymbol]=>>###
[fmtr stringFromNumber:nil]=>>(null)
[fmtr stringFromNumber:0]=>>0000
[fmtr stringFromNumber:null]=>>(null)
[fmtr numberFromString:nil]=(null)
[fmtr numberFromString:@"0"]=0
[fmtr numberFromString:NULL]=(null)
【问题讨论】:
标签: iphone objective-c ios nsnumberformatter