官方将文件size转换为MGB字符串
来源:互联网 发布:焦作市青峰网络 编辑:程序博客网 时间:2024/04/27 13:52
//功能:将字节大小(Kb)转换为Gb或Mb
//参数:KbSizestr: 以Kb为单位的size字符串
//返回值:转换为Gb或Mb的字符串
NSString * formattedFileSize(unsigned long long size)
{
NSString *formattedStr = nil;
if (size == 0)
formattedStr = @"Empty";
else
if (size > 0 && size < 1024)
formattedStr = [NSString stringWithFormat:@"%qu bytes", size];
else
if (size >= 1024 && size < pow(1024, 2))
formattedStr = [NSString stringWithFormat:@"%.1f KB", (size / 1024.)];
else
if (size >= pow(1024, 2) && size < pow(1024, 3))
formattedStr = [NSString stringWithFormat:@"%.2f MB", (size / pow(1024, 2))];
else
if (size >= pow(1024, 3))
formattedStr = [NSString stringWithFormat:@"%.3f GB", (size / pow(1024, 3))];
return formattedStr;
}
//参数:KbSizestr: 以Kb为单位的size字符串
//返回值:转换为Gb或Mb的字符串
NSString * formattedFileSize(unsigned long long size)
{
NSString *formattedStr = nil;
if (size == 0)
formattedStr = @"Empty";
else
if (size > 0 && size < 1024)
formattedStr = [NSString stringWithFormat:@"%qu bytes", size];
else
if (size >= 1024 && size < pow(1024, 2))
formattedStr = [NSString stringWithFormat:@"%.1f KB", (size / 1024.)];
else
if (size >= pow(1024, 2) && size < pow(1024, 3))
formattedStr = [NSString stringWithFormat:@"%.2f MB", (size / pow(1024, 2))];
else
if (size >= pow(1024, 3))
formattedStr = [NSString stringWithFormat:@"%.3f GB", (size / pow(1024, 3))];
return formattedStr;
}
- 官方将文件size转换为MGB字符串
- 文件转换为字符串
- 将字符串转换为数值
- 将字符串转换为大写
- 将整数转换为字符串
- 将数字转换为字符串
- 将数字转换为字符串
- 将数字转换为字符串
- 将字符串转换为整数
- 将字符串转换为数字
- 将字符串转换为数字
- 将字符串转换为整数
- 将字符串转换为数字
- 将字符串转换为整数
- 将字符串转换为数字
- 将字符串转换为整数
- 将字符串转换为整数
- 将格林威治时间转换为字符串
- Asterisk 所有的通道变量名称
- IPTV视频传输质量测试标准 - RFC4445 MDI (Media Delivery Index)媒体传输质量指标详解
- iOS5编程--官方例子代码的研究--2.UICatalog-5
- 对于近期预算编写工作效率的反思
- 这么生僻呀 先保存 以备不时只需
- 官方将文件size转换为MGB字符串
- redhat AS 5安装ORACLE10g
- 项目经理问:我怎么有做不完的事情 – 事件篮方法
- 诡异的ExtJs提交表单报错
- AGI脚本说明
- c# 爱情
- 为何ERP实施失败率一直很高?
- ERROR:TNS-12535: TNS: 操作超时
- drupal7安装与删除