views:

129

answers:

1

Apple has (apparently) changed how they calculate KB, MB, and GB in 10.6. Instead of using 1024, they use 1000. (As described here: http://reviews.cnet.com/8301-13727_7-10330509-263.html)

My question is how do deal with this in my code? I'm trying to get the amount of space free, so I get the number of bytes via NSFileManager. When I go to display that to the user, I need to turn that into GBs differently depending on whether they're on 10.5 or 10.6.

Is there a built-in constant for GB size? (Or whatever it is you would call the 1024 number? ) It seemed a little silly to define my own.

## I'm currently doing something like this.
if (running10_6) {
    double gbConst = 1000 * 1000 * 1000;
} else {
    double gbConst = 1024 * 1024 * 1024;
}

NSDictionary *attr = [NSFM attributesOfFileSystemForPath:@"/" error:nil];
double bytes = [[attr objectForKey:NSFileSystemFreeSize] doubleValue];
double freeGB = bytes / gbConst;
+1  A: 

I have not find anything in Cocoa or IOKit reference. All the size functions return a value in bytes. So it is up the UI to deal with the formatting. So your solution seems the right way to go.

Laurent Etiemble