开发者

how do I round numbers with NSNumberFormatter

I've got a calculation for example 57 / 30 so the solution will开发者_开发知识库 be 1,766666667.. How do i first of all get the 1,766666667 i only get 1 or 1.00 and then how do i round the solution (to be 2)?

thanks a lot!


57/30 performs integer division. To obtain a float (or double) result you should make 1 of the operands a floating point value:

result = 57.0/30;

To round result have a look at standard floor and ceil functions.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜