I don't understand how NSNumberFormatterPercentStyle works!
Example:
NSNumber *number = [NSNumber numberWithFloat:90.5]; NSNumberFormatter *percentageFormatter = [[[NSNumberFormatter alloc] init] autorelease]; [percentageFormatter setNumberStyle:NSNumberFormatterPercentStyle]; NSString *strNumber = [percentageFormatter stringFromNumber:numbericString]; NSLog (strNumber); // Output: 9,050%
I simply want to show "90.5%" (respecting NSLocal). What is NSNumberFormatterPercentStyle doing with 90.5, and why? And, how can i get my desired result!?
Just set the multiplier to 1
if your numbers are already in percentage.
numberFormatter = [[NSNumberFormatter alloc] init]; [numberFormatter setNumberStyle:NSNumberFormatterPercentStyle]; [numberFormatter setMaximumFractionDigits:0]; [numberFormatter setMultiplier:@1];
Its presuming that the number is in the range of 0-1, as it is a percent
so 0.905 would get you 90.5%.
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