标签:int als port else rom ima sel substr number
@interface NSString (RMB) - (NSString *)RMBFormatString; @end #import "NSString+RMB.h" @implementation NSString (RMB) - (NSString *)RMBFormatString { NSString *number = self; if ([number doubleValue] > 0) { number = [NSString stringWithFormat:@"%.2f",[number doubleValue]]; NSNumberFormatter *numFormatter = [[NSNumberFormatter alloc]init]; numFormatter.numberStyle = NSNumberFormatterDecimalStyle; NSNumber *num = [NSNumber numberWithDouble:[number doubleValue]]; NSString *str = [NSString stringWithFormat:@"%@",[numFormatter stringFromNumber:num]]; if ([str rangeOfString:@"."].length > 0) { NSString *floatStr = [str componentsSeparatedByString:@"."][1]; if (floatStr.length == 1) { str = [NSString stringWithFormat:@"%@0",str]; } else{ str = [str substringToIndex:([str rangeOfString:@"."].location + 3)]; } return [NSString stringWithFormat:@"¥%@",str]; } else{ return [NSString stringWithFormat:@"¥%@.00",str]; } } else { return @"¥0.00"; } } @end
标签:int als port else rom ima sel substr number
原文地址:http://www.cnblogs.com/muzijie/p/7262075.html