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
]
相關文章
相關標籤/搜索