您好,欢迎来到二三娱乐。
搜索
您的当前位置:首页计算下载大小和单位值

计算下载大小和单位值

来源:二三娱乐

// 计算大小, 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"; }

}

Copyright © 2019- yule263.com 版权所有 湘ICP备2023023988号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务