Changeset 423
- Timestamp:
- Jun 21, 2006, 5:14:50 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/macosx/StringAdditions.m
r422 r423 47 47 return [NSString stringWithFormat: @"%lld bytes", size]; 48 48 49 float displaySize = (float) size / 1024.0;49 float convertedSize = (float) size; 50 50 NSString * unit; 51 51 if (size < 1048576) 52 { 53 convertedSize /= 1024.0; 52 54 unit = @" KB"; 55 } 53 56 else if (size < 1073741824) 54 57 { 55 displaySize /= 1024.0;58 convertedSize /= 1048576.0; 56 59 unit = @" MB"; 57 60 } 58 61 else 59 62 { 60 displaySize /= 1048576.0;63 convertedSize /= 1073741824.0; 61 64 unit = @" GB"; 62 65 } 63 66 64 67 NSString * value; 65 if (displaySize < 10.0) 66 value = [NSString stringWithFormat: @"%.2f", displaySize]; 67 else if (displaySize < 100.0) 68 value = [NSString stringWithFormat: @"%.1f", displaySize]; 68 //attempt to have values with 3 digits 69 if (convertedSize < 10.0) 70 value = [NSString stringWithFormat: @"%.2f", convertedSize]; 71 else if (convertedSize < 100.0) 72 value = [NSString stringWithFormat: @"%.1f", convertedSize]; 69 73 else 70 value = [NSString stringWithFormat: @"%.0f", displaySize];74 value = [NSString stringWithFormat: @"%.0f", convertedSize]; 71 75 72 76 return [value stringByAppendingString: unit];
Note: See TracChangeset
for help on using the changeset viewer.