`

12000.34 -> 12,000

    博客分类:
  • iOS
 
阅读更多

//convert double to needed NSString,such 12000.34 -> 12,000


- (NSString *)convertDoubleToString: (double)doub {
    NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
    [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
    NSString *distanceStr = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:doub]];
    distanceStr = [distanceStr substringFromIndex:1];
    NSRange ran = [distanceStr rangeOfString:@"."];
    distanceStr = [distanceStr substringToIndex:ran.location];
    return distanceStr;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics