Possible Duplicate:
ObjC/Cocoa class for converting size to human-readable string?
I’m new in Cocoa. I’m trying to get size of folder files properly. And display it in MB if it less 1 GB , or in GB.
The way I want it to display is rounded with one number after point.
Example
5.5 MB if it is more than 1000 > 1.1 GB
I’m trying to use this
unsigned long long size= ([[[NSFileManager defaultManager] attributesOfItemAtPath:fullPath error:nil] fileSize]);
But I can’t a way properly convert number, and display it , as I want.
Thanks.
For converting file size to MB, Gb use below function
EDIT:
You can also use NSByteCountFormatter class. Available in iOS 6.0 / OS X v10.8 and later.
You can use
NSByteCountFormatterCountStyleFile,NSByteCountFormatterCountStyleMemory,NSByteCountFormatterCountStyleDecimalorNSByteCountFormatterCountStyleBinaryin countStyle.