开发者

How to control the scientifc style of NSNumberFormatter?

I'm converting a long string representing a very big or small number to a s开发者_运维百科tring in scientific notation. E.g. 9999999999999999999999999 to 9.999999999999999E24.

I use NSNumberFormatter.

NSNumberFormatter *ns = [[NSNumberFormatter alloc] init];
[ns setNumberStyle: NSNumberFormatterScientificStyle];
NSString *result = [ns stringFromNumber: [ns numberFromString: aBigOrSmallString]];
[ns release];

But how can I control the precision part? For example, from 912345678 to 9.12E8 or 9.1234E8.


Have you checked the setMinimumFractionDigits and setMaximumFractionDigits
Reference: NSNumberFormatter Class Reference

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜