开发者

obj-c : iphone programming disabling the round off of a number

i need to show a number to a user : 1.96666777 (timeHour)

moduloformat = [NSString stringWithFormat:@"%0.0f hours ",timeHour];

but it is rounding off the number automaticly. It gives "2" and i want to show "1" i could us开发者_StackOverflow中文版e a NSrange and take the first number but i wanna know how to deal with this. Thanks!!


moduloformat = [NSString stringWithFormat:@"%0.0f hours ",floor( timeHour )];


Easiest to just cast the float to an int. When you do that the decimal places get chopped off and no rounding occurs.

moduloformat = [NSString stringWithFormat:@"%i hours ", (int)timeHour];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜