I'm able to convert a particular NSNumber into currency using NSNUmberFormatter. Its showign $ symbol, numbers separated by "," etc.
But I don't want to display cents.
For example its displaying $537,335.32
I just want to display $536,335
I'm writing the following code:
NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSDictionary* tempDict = [self.displayDict objectForKey:kConservative];
conservativeHP.text = [currencyFormatter stringFromNumber:[tempDict objectForKey:kHomePrice]];
How should I create NSNumberFormatter or do something so that the result won't have "decimals"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With