iOS开发_文件大小格式化显示
作者:互联网
// 文件大小格式化显示
- (NSString *)convert_FileSize:(long long)file_size {
long kb = 1024;
long mb = kb * 1024;
long gb = mb * 1024;
if (file_size >= gb) {
return [NSString stringWithFormat:@"%.1f GB", (float) file_size / gb];
}
else if (file_size >= mb) {
float gc_float = (float) file_size / mb;
if (gc_float > 100) {
return [NSString stringWithFormat:@"%.0f MB", gc_float];
}
else {
return [NSString stringWithFormat:@"%.1f MB", gc_float];
}
}
else if (file_size >= kb) {
float gc_float = (float) file_size / kb;
if (gc_float > 100) {
return [NSString stringWithFormat:@"%.0f KB", gc_float];
}
else {
return [NSString stringWithFormat:@"%.1f KB", gc_float];
}
} else
return [NSString stringWithFormat:@"%lld B", file_size];
}
标签:文件大小,格式化,float,iOS,stringWithFormat,NSString,gc,file,size 来源: https://www.cnblogs.com/CH520/p/15823476.html