iOS - Showing currency without cents using NSNumberFormatter iOS - Showing currency without cents using NSNumberFormatter ios ios

iOS - Showing currency without cents using NSNumberFormatter


Use the maximumFractionDigits setting:

NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease];[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];[currencyFormatter setMaximumFractionDigits:2];

You can adjust the value accordingly. Using 2 will limit the result to two digits, for this question a value of 0 should do it.


Here is solution in swift 3

    let formatter = NumberFormatter()    formatter.numberStyle = .currency    //formatter.locale = NSLocale.current    formatter.currencySymbol = "" //In case you do not want any currency symbols    formatter.maximumFractionDigits = 0

Setting the maximumFractionDigits to 0 will not show any decimal or fractional values.


Swift 3:

currencyFormatter.maximumFractionDigits = 0