Changeset 3186


Ignore:
Timestamp:
Sep 26, 2007, 4:18:18 PM (15 years ago)
Author:
livings124
Message:

for file size always show at least one decimal place

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/NSStringAdditions.m

    r3083 r3186  
    4848    {
    4949        convertedSize = size / 1024.0;
    50         unit = NSLocalizedString(@" KB", "File size (beware of leading space)");
     50        unit = NSLocalizedString(@"KB", "File size (beware of leading space)");
    5151    }
    5252    else if (size < 1073741824)
    5353    {
    5454        convertedSize = size / 1048576.0;
    55         unit = NSLocalizedString(@" MB", "File size (beware of leading space)");
     55        unit = NSLocalizedString(@"MB", "File size (beware of leading space)");
    5656    }
    5757    else
    5858    {
    5959        convertedSize = size / 1073741824.0;
    60         unit = NSLocalizedString(@" GB", "File size (beware of leading space)");
     60        unit = NSLocalizedString(@"GB", "File size (beware of leading space)");
    6161    }
    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];
    7365}
    7466
Note: See TracChangeset for help on using the changeset viewer.