It sounds like you’re working with currencies. If so, you should check out NSDecimalNumber, which is a fixed point number format. Mixing floating point and currencies will generally end badly because binary floating point is unable to represent simple decimal values (like 0.1) without losing accuracy.
With regards NSNumberFormatter, if you want to control how many fractional digits it shows you can do that using the
maximumFractionDigitsproperties. For example:
import Foundation let nf = NSNumberFormatter() nf.numberStyle = .DecimalStyle nf.minimumFractionDigits = 3 nf.maximumFractionDigits = 3 print(nf.stringFromNumber(0.123)!) // -> “0.123”
Share and Enjoy
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"