Changeset 3186
- Timestamp:
- Sep 26, 2007, 4:18:18 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/macosx/NSStringAdditions.m
r3083 r3186 48 48 { 49 49 convertedSize = size / 1024.0; 50 unit = NSLocalizedString(@" 50 unit = NSLocalizedString(@"KB", "File size (beware of leading space)"); 51 51 } 52 52 else if (size < 1073741824) 53 53 { 54 54 convertedSize = size / 1048576.0; 55 unit = NSLocalizedString(@" 55 unit = NSLocalizedString(@"MB", "File size (beware of leading space)"); 56 56 } 57 57 else 58 58 { 59 59 convertedSize = size / 1073741824.0; 60 unit = NSLocalizedString(@" 60 unit = NSLocalizedString(@"GB", "File size (beware of leading space)"); 61 61 } 62 63 NSString * sizeString; 64 //attempt to have values with 3 digits 65 if (convertedSize < 10.0) 66 sizeString = [NSString stringWithFormat: @"%.2f", convertedSize]; 67 else if (convertedSize < 100.0) 68 sizeString = [NSString stringWithFormat: @"%.1f", convertedSize]; 69 else 70 sizeString = [NSString stringWithFormat: @"%.0f", convertedSize]; 71 72 return [sizeString stringByAppendingString: unit]; 62 63 //attempt to have minimum of 3 digits with at least 1 decimal 64 return [NSString stringWithFormat: convertedSize < 10.0 ? @"%.2f %@" : @"%.1f %@", convertedSize, unit]; 73 65 } 74 66
Note: See TracChangeset
for help on using the changeset viewer.