Formatting EDIT
This is how I did it when I needed to display the currency (but integers if the currency was a round number.
First we get the amount of money as a string
NSString *earnString = _money.payout.displayableAmount; NSMutableString *strippedString = [NSMutableString stringWithCapacity:earnString.length];
// scan the string to remove anything other than numbers (including decimal points)
NSScanner *scanner = [NSScanner scannerWithString:earnString]; NSCharacterSet *numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"]; while ([scanner isAtEnd] == NO) { NSString *buffer; if ([scanner scanCharactersFromSet:numbers intoString:&buffer]) { [strippedString appendString:buffer]; } else { [scanner setScanLocation:([scanner scanLocation] + 1)]; } }
// if the string is less than 100, then we only had a βchangeβ to display this amount if (earnInt <100) {// The dollar amount is less than the dollar indication only in cents and the cent symbol NSString * centString = [NSString stringWithFormat: @ " % i Β’ ", earnInt]; earnAmount.text = centString;
// if we have a number evenly divisible by 100, then we have an integer amount in dollars, display it correctly} else if (earnInt% 100 == 0) {
// finally, if we have a mixed number, then return them back along with the decimal space.
}else{ //Dollar amount is not exactly a dollar display the entire amount NSString *dollarString = [NSString stringWithFormat: @"$%0d.%02d", (earnInt / 100), (earnInt % 100)]; earnAmount.text = dollarString; }
Hope this helps you ...
source share