'''
NSNumber *number = [NSNumber numberWithDouble:9.20];
NSString *numString1 = [NSString stringWithFormat:@"%@",number];
NSLog(@"方式1 ****** %@",numString1);
NSString *numString2 = [number description];
NSLog(@"方式2 ****** %@",numString2);
NSString *numString3 = [NSString stringWithFormat:@"%f",number.doubleValue];
NSLog(@"方式3 ****** %@",numString3);
NSNumberFormatter *numberFormat = [[NSNumberFormatter alloc] init];
NSString *numString4 = [numberFormat stringFromNumber:number];
NSLog(@"方式4 ****** %@",numString4);
NSNumberFormatter *numberFormat3 = [[NSNumberFormatter alloc] init];
numberFormat3.numberStyle = NSNumberFormatterDecimalStyle;
NSString *numString5 = [numberFormat3 stringFromNumber:number];
NSLog(@"方式5 ****** %@",numString5);
NSDecimalNumber *decNumber = [NSDecimalNumber decimalNumberWithString:number.stringValue];
NSString * numString6 = [decNumber stringValue];
NSLog(@"方式6 ****** %@",numString6);
NSNumberFormatter *numberFormat7 = [[NSNumberFormatter alloc] init];
[numberFormat7 setPositiveFormat:@"########.########"];
NSString *numString7 = [numberFormat7 stringFromNumber:number];
NSLog(@"方式7 ****** %@",numString7);
'''
看一下结果
'''
2020-04-29 18:25:17.588119+0800 金融货币[77778:9065081] 方式1 ****** 9.199999999999999
2020-04-29 18:25:17.588330+0800 金融货币[77778:9065081] 方式2 ****** 9.199999999999999
2020-04-29 18:25:17.588459+0800 金融货币[77778:9065081] 方式3 ****** 9.200000
2020-04-29 18:25:17.589121+0800 金融货币[77778:9065081] 方式4 ****** 9
2020-04-29 18:25:17.589469+0800 金融货币[77778:9065081] 方式5 ****** 9.2
2020-04-29 18:25:17.589686+0800 金融货币[77778:9065081] 方式6 ****** 9.199999999999999
2020-04-29 18:25:17.590102+0800 金融货币[77778:9065081] 方式7 ****** 9.2
'''
网友评论