My app has a picker that has numbers with suffix of lbs. I want to add support for user to be able to use kgs instead. So I tried using this:
NSNumber *weightInPounds = [pickerArray objectAtIndex:row];
NSNumber *weightInKilos = [[DDUnitConverter massUnitConverter] convertNumber: weightInPounds fromUnit: DDMassUnitUSPounds toUnit: DDMassUnitKilograms];
float roundedValue = round(2.0f * [weightInKilos floatValue]) / 2.0f;
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:1];
[formatter setRoundingMode: NSNumberFormatterRoundDown];
NSString *numberString = [formatter stringFromNumber:[NSNumber numberWithFloat:roundedValue]];
label.text = numberString;
[formatter release];
Using that code, it rounds to the nearest .5 or .0. The problem is that the increments are not consistent. Like its not 1, 1.5, 2, 2.5, 3, etc. Its coming out more like 1, 2, 3.5, 4.5, 5, etc. I think this is because when lbs are converted to kgs, that is the way it comes out. But I don't think the user will want the numbers displayed like that. It seems like they would want normal increments of .5 kgs. Does anyone know how I can fix this?