/*
* 小数点后面有几位就保留几位
*/
CGFloat reduce = [model.benprice floatValue];
NSString* redStr = @"";
if (fmodf(reduce, 1)==0) {
redStr = [NSString stringWithFormat:@"%.0f",reduce];
} else if (fmodf(reduce*10, 1)==0) {
redStr = [NSString stringWithFormat:@"%.1f",reduce];
} else {
redStr = [NSString stringWithFormat:@"%.2f",reduce];
}
moneyLabel.text = [NSString stringWithFormat:@"¥ %@",redStr];
//计算文件的大小
+(NSString *)getFileSizestring:(NSString *)size{
CGFloat sizeFloat;
if ([size floatValue] > 1024 * 1024 *1024) {//大于1G 则转化为G为单位的字符串
sizeFloat = [size floatValue] / 1024 / 1024 / 1024;
return [NSString stringWithFormat:@"%.1fG",[size floatValue]/ 1024/ 1024/ 1024];
}else if ([size floatValue] >= 1024*1024) {//大于1M 则转化为M单位的字符串
sizeFloat = [size floatValue] / 1024 / 1024 / 1024;
return [NSString stringWithFormat:@"%0.1fM",[size floatValue]/1024/1024];
}else if ([size floatValue] >= 1024 && [size floatValue] < 1024 * 1024){//不到1M但是超过了1KB,则转化成KB单位
sizeFloat = [size floatValue] / 1024 / 1024 / 1024;
return [NSString stringWithFormat:@"%0.1fKB",[size floatValue]/1024];
}else{//剩下的都是小鱼1k的,则转化为B单位
sizeFloat = [size floatValue] / 1024 / 1024 / 1024;
return [NSString stringWithFormat:@"%0.1fB",[size floatValue]];
}
if (fmodf(sizeFloat, 1)==0) {
return [NSString stringWithFormat:@"%.0f",sizeFloat];
} else if (fmodf(sizeFloat*10, 1)==0) {
return [NSString stringWithFormat:@"%.1f",sizeFloat];
} else {
return [NSString stringWithFormat:@"%.2f",sizeFloat];
}
}