// Returns a human-readable string showing the file size from the number of bytes
1
2 - (NSString *)stringFromFileSize:(int)theSize
3 {
4 float floatSize = theSize;
5 if (theSize<1023)
6 return([NSString stringWithFormat:@"%i bytes",theSize]);
7 floatSize = floatSize / 1024;
8 if (floatSize<1023)
9 return([NSString stringWithFormat:@"%1.1f KB",floatSize]);
10 floatSize = floatSize / 1024;
11 if (floatSize<1023)
12 return([NSString stringWithFormat:@"%1.1f MB",floatSize]);
13 floatSize = floatSize / 1024;
14
15 // Add as many as you like
16
17 return([NSString stringWithFormat:@"%1.1f GB",floatSize]);
18 }