iOS - 浮点数去掉小数点之后的0,以0.5小数递增函数

 

NSMutableArray *arrNumber = [NSMutableArray array];
    float a = -0.5;
    while (a<5) {
        a+=0.5;
        NSString *str = [self removeFloatAllZeroByString:[NSString stringWithFormat:@"%.1f",a]];
        [arrNumber addObject:str];
    }
    NSLog(@"%@",arrNumber);


//浮点数去掉小数点之后的0
- (NSString*)removeFloatAllZeroByString:(NSString *)testNumber{
    NSString * outNumber = [NSString stringWithFormat:@"%@",@(testNumber.floatValue)];
    return outNumber;
}
 [
0,
0.5,
1,
1.5,
2,
2.5,
3,
3.5,
4,
4.5,
5
]

 

posted @ 2019-09-26 16:54  公羽寒  阅读(526)  评论(0编辑  收藏  举报