views:

52

answers:

1

I need to convert NSFileSystemSize to Gigabytes.

NSDictionary * fsAttributes = [ [NSFileManager defaultManager]
       fileSystemAttributesAtPath:NSTemporaryDirectory()];
NSNumber *totalSize = [fsAttributes objectForKey:NSFileSystemSize];
NSString *sizeInGB = [NSString stringWithFormat:@"\n\n %3.2f GB",[totalSize floatValue] / 107374824];

//returns 69.86 GB

any ideas why it doesnt return at leat 8.0GB's?

A: 

As a nit, 1024 * 1024 * 1024 is 1073741824, not 107374824 (you're missing a 1 in the thousands place.)

fbrereto
Nice catch. I actually went with: NSString *sizeInGB = [NSString stringWithFormat:@"\n\n%.2f GB",[totalSize floatValue] / 1024 / 1024 / 1024]; seems to have worked correctly.
AWright4911