- 补充
NSNumberFormatter *numberFormatter = [NSNumberFormatter new];
numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
numberFormatter.multiplier = @1000;
NSLog(@"%@千",[numberFormatter numberFromString:@"1000"]); // 1千
NSLog(@"%@千",[numberFormatter stringFromNumber:@0.001]); // 1千
关于multiplier
(缩放因子)的说明:当 numberFormatter
接收的是 NSNumber
类型时,最终的结果为:number * multiplier
,当接收的是 NSString
类型时,结果为:string / multiplier
。
- 官方文档:
A multiplier is a factor used in conversions between numbers and
strings (that is, numbers as stored and numbers as displayed).
When the input value is a string, the multiplier is used to divide,
and when the input value is a number, the multiplier is used to
multiply. These operations allow the formatted values to be
different from the values that a program manipulates internally.