Changeset 423


Ignore:
Timestamp:
Jun 21, 2006, 5:14:50 PM (17 years ago)
Author:
livings124
Message:

refine string formatting a tiny bit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/StringAdditions.m

    r422 r423  
    4747        return [NSString stringWithFormat: @"%lld bytes", size];
    4848
    49     float displaySize = (float) size / 1024.0;
     49    float convertedSize = (float) size;
    5050    NSString * unit;
    5151    if (size < 1048576)
     52    {
     53        convertedSize /= 1024.0;
    5254        unit = @" KB";
     55    }
    5356    else if (size < 1073741824)
    5457    {
    55         displaySize /= 1024.0;
     58        convertedSize /= 1048576.0;
    5659        unit = @" MB";
    5760    }
    5861    else
    5962    {
    60         displaySize /= 1048576.0;
     63        convertedSize /= 1073741824.0;
    6164        unit = @" GB";
    6265    }
    6366
    6467    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];
    6973    else
    70         value = [NSString stringWithFormat: @"%.0f", displaySize];
     74        value = [NSString stringWithFormat: @"%.0f", convertedSize];
    7175
    7276    return [value stringByAppendingString: unit];
Note: See TracChangeset for help on using the changeset viewer.