iOS面试

iOS保留有效小数

2018-02-28  本文已影响601人  泛坷
- (NSString *)limitFloatValue:(CGFloat)value{
    if (fmodf(value, 1)==0) {//如果有一位小数点
        return [NSString stringWithFormat:@"¥%.0f",value];
    } else if (fmodf(value*10, 1)==0) {//如果有两位小数点
        return [NSString stringWithFormat:@"¥%.1f",value];
    }else {
        return [NSString stringWithFormat:@"¥%.2f",value];
    }
}
上一篇 下一篇

猜你喜欢

热点阅读