开发者

how do I round numbers with NSNumberFormatter

开发者 https://www.devze.com 2022-12-12 17:17 出处:网络
I\'ve got a calculation for example 57 / 30 so the solution will开发者_开发知识库 be 1,766666667..

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

精彩评论

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

关注公众号