计算下载大小和单位值
// 计算大小, 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";
}
}
推荐阅读
- 我要做大厨
- 《真与假的困惑》???|《真与假的困惑》??? ——致良知是一种伟大的力量
- 知识
- 三十年后的广场舞大爷
- 奔向你的城市
- 村里的故事|村里的故事 --赵大头
- 期刊|期刊 | 国内核心期刊之(北大核心)
- 华为旁!大社区、地铁新盘,佳兆业城市广场五期!
- 汇讲-勇于突破
- 每日一话(49)——一位清华教授在朋友圈给大学生的9条建议