开发者

How to represent NSNumber with scientific notation?

I use [NSNumber numberWithDouble:] method to form my NSNumber. H开发者_JAVA技巧owever, since some of the values might be large, I want to know if there is a way to tell NSNumber to represent itself with the scientific notation. Thanks in advance!


Take a look at NSDecimalNumber. They allow for higher precision than NSNumber, and support scientific notation and other features.


Try turning the number into as string and use the scientific print formatter %e, or %E

I say this because there is no point in trying to get the NSNumber to format itself because it is only an object wrapper around a value. When you want to present the number, then treat it as a string and use the NSString methods to show the value in the way that you want.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜