Created
March 21, 2016 02:29
-
-
Save CaliosD/434c6e17f9752df710bb to your computer and use it in GitHub Desktop.
求文件大小
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)formattedFileSize:(unsignedlonglong)size | |
{ | |
NSString *formattedStr = nil; | |
if (size == 0) | |
formattedStr = @"Empty"; | |
else | |
if (size > 0 && size < 1024) | |
formattedStr = [NSStringstringWithFormat:@"%qu bytes", size]; | |
// Lilac-Annotation: %qu: Unsigned 64-bit integer (unsigned long long) | |
else | |
if (size >= 1024 && size < pow(1024, 2)) | |
formattedStr = [NSStringstringWithFormat:@"%.1f KB", (size / 1024.)]; | |
else | |
if (size >= pow(1024, 2) && size < pow(1024, 3)) | |
formattedStr = [NSStringstringWithFormat:@"%.2f MB", (size / pow(1024, 2))]; | |
// Lilac-Annotation: pow(x,y),计算x的y次幂 | |
else | |
if (size >= pow(1024, 3)) | |
formattedStr = [NSStringstringWithFormat:@"%.3f GB", (size / pow(1024, 3))]; | |
return formattedStr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment