NSArray *arr = @[@"5.0",@"1.0",@"4.0",@"3.0",@"4.4",@"10.7",@"6.0",@"14.5",@"16.4",@"30.2",@"20.8",@"18.6"];
float sum = [[arr valueForKeyPath:@"@sum.floatValue"] floatValue];//求和
float avg = [[arr valueForKeyPath:@"@avg.floatValue"] floatValue];//求平均值
float max = [[arr valueForKeyPath:@"@max.floatValue"] floatValue];//求最大值
float min = [[arr valueForKeyPath:@"@min.floatValue"] floatValue];//求最小值
NSLog(@"和:%f \n 平均值:%f \n 最大值:%f \n 最小值:%f",sum,avg,max,min);
网友评论