我有一个UILabel及其格式化程序:
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[formatter setGroupingSeparator:@"."];
[formatter setGroupingSize:3];
[formatter setAlwaysShowsDecimalSeparator:NO];
[formatter setUsesGroupingSeparator:YES];
[formatter setDecimalSeparator:@","];
NSString *formattedString = [formatter stringFromNumber:[NSNumber numberWithFloat:12.]]];
这样我的formattedString返回12
如果我想在没有小数的情况下保留逗号怎么办?所以我的UIlabel打印出“12”。
答案 0 :(得分:0)
如果您想在没有小数时看到逗号,请相应地设置alwaysShowsDecimalSeparator
[formatter setAlwaysShowsDecimalSeparator:YES];
因此,您的UILabel
会说“12”,而不是“12”。