我正在创建描述标注,我希望描述标注的高度应取决于从表达式四舍五入的值
NSString *description = [dic objectForKey:@"des"];
UIFont *font = [UIFont boldSystemFontOfSize:8];
CGSize desSize = [description sizeWithFont:font];
float hgt = desSize.width / userView.frame.size.width;我希望hgt的值应该是精确的数字,比如如果输出值是0.1,那么hgt的值应该是1,另一个类似的情况是,如果差的o/p的值是3.3,那么hgt应该变成4。
请帮我解决这个问题
发布于 2011-12-26 17:58:22
使用ceil()向上舍入。
float hgt = ceil(desSize.width / userView.frame.size.width);发布于 2011-12-26 17:58:29
您想要使用ceil()。这会将数字向上舍入到最接近的整数。
发布于 2011-12-26 22:28:10
fabs() – Find the absolute value or unsigned value in parentheses.
result = fabs(x); // fabs(-2.5) = 2.5
ceil() – To round up
i = ceil(x); // ceil(3.5) = 4
floor() – find the integer that is below the floating point value.
i = floor(x); // floor(4.2) = 4
pow() – raise a number to the power.
i = pow(x,y); //pow(4,2) = 16
sqrt() – Square root of a number.
i = sqrt(x); // sqrt(16) = 4
exp() – find the expoential value.https://stackoverflow.com/questions/8634638
复制相似问题