Friday, July 12, 2013

How Not to Round

Found this gem in some code (not mine!) today:
NSString *precisionTwoString = [NSString stringWithFormat:@"%.2f",
    ((minRequiredLabelSize.width + 16.0) /
    self.credentialInputTableView.frame.size.width)];

__labelProportion = [precisionTwoString floatValue];
Those two digits so meticulously "preserved?" Irrelevant. Obviously, ceil() was too complicated.