Tag: float string price.
2988.32--> 2,988.32
2988.00--> 2,988
+ (nsstring *) Pricestrwithprice: (float) price{ nsstring *pricestr = [nsstring stringwithformat:@ "%.2f", price]; nsstring *intstr = [[pricestr componentsseparatedbystring:@ "."] firstObject]; NSString *dotStr = [[priceStr componentsseparatedbystring:@ "."] lastobject]; nsmutablearray *array = [ nsmutablearray array]; while ([intstr length] > 3) { NSString *right = [intStr substringfromindex:[intstr length] - 3]; nsstring *left= [intstr substringtoindex:[intstr length] - 3]; [array insertobject:right atindex:0]; intstr = left; } [array insertObject:intStr atIndex:0]; nsstring *result = [array componentsjoinedbystring:@ ","]; if ( [Dotstr intvalue] > 0] { result = [nsstring stringwithformat:@ "%@.%@", result, dotstr]; } return result;}
Convert price (float) to a delimited price (string)