saurb
saurb

Reputation: 685

How to represent NSNumber with scientific notation?

I use [NSNumber numberWithDouble:] method to form my NSNumber. However, 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!

Upvotes: 0

Views: 739

Answers (2)

Abizern
Abizern

Reputation: 150615

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.

Upvotes: 1

Cameron Spickert
Cameron Spickert

Reputation: 5200

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

Upvotes: 2

Related Questions