How to control the scientifc style of NSNumberFormatter?

别等时光非礼了梦想. 提交于 2020-02-24 18:00:48

问题


I'm converting a long string representing a very big or small number to a string 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.


回答1:


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



来源:https://stackoverflow.com/questions/2215867/how-to-control-the-scientifc-style-of-nsnumberformatter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!