I use NSNumberFormatter to format the currency, but formatting does not work when I use float. However, it works when I use double. I need it to work with floats, since I do not need to work in dual mode.
float t1 = 999999.99; NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; [formatter setNumberStyle:NSNumberFormatterCurrencyStyle]; [formatter setAllowsFloats:YES]; [formatter setMaximumFractionDigits:2]; [formatter setAlwaysShowsDecimalSeparator:YES]; [formatter setGeneratesDecimalNumbers:YES]; NSString *formattedOutput = [formatter stringFromNumber:[NSNumber numberWithFloat:t1]]; NSLog(@"Output as currency: %@", formattedOutput);
these exits are currency exits: $ 1,000,000.00 and not $ 9,99,999.99
Thanks in advance for your help.
source share