iOS

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
]
原文地址:https://www.cnblogs.com/gongyuhonglou/p/11592840.html