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 ]
天行健,君子以自强不息;地势坤,君子以厚德载物!