Round NSNumber to a specific number of significant digits

Viewed 555

Let's say I have an NSNumber object that holds a value 0.12345. All I want is an NSNumber object with a same value, but rounded to a specified number of significant digits, say 2, so value looks like this: 0.12.

  • I don't want to convert it to NSString and back, which is what some of the answers suggest
  • I would prefer not to cast/convert and/or do multiplication/division manually like in this answer

Is there an obvious way to do it that I am missing?

2 Answers
Related