计算下载大小和单位值

// 计算大小, pow是次方表达式
- (float)calculateFileSizeInUnit:(unsigned long long)contentLength

{
if(contentLength >= pow(1024, 3)) { return (float) (contentLength / (float)pow(1024, 3)); }
else if (contentLength >= pow(1024, 2)) { return (float) (contentLength / (float)pow(1024, 2)); }
else if (contentLength >= 1024) { return (float) (contentLength / (float)1024); }
else { return (float) (contentLength); }
}
// 计算单位值
- (NSString *)calculateUnit:(unsigned long long)contentLength
{
if(contentLength >= pow(1024, 3)) { return @"GB"; }
【计算下载大小和单位值】else if(contentLength >= pow(1024, 2)) { return @"MB"; }
else if(contentLength >= 1024) { return @"KB"; }
else { return @"B"; }
}

    推荐阅读