开发者

Rounding down with a number. Finding the n in n.mp

Bit of an odd question. I'm using cocoa.

I have a series of numbers e.g.:

0.87

0.32

1.12

2.34

8.82

12.66

and I want to get the bit 开发者_C百科before the decimal place, with no rounding.

Like this:

0.87 -> 0

0.32 -> 0

1.12 -> 1

2.34 -> 2

8.82 -> 8

12.66 -> 12

I can round the numbers with no problem, but I can't figure out how to just take the 'rounded down' figure in an elegant and non complicated way. Can you help?


use floor(double). Or cast to an int


Simply cast it to an int and you're good to go.

NSLog(@"n is %i", n);

%i will automatically cast it to int. :P


float x = 0.89;
int y = x;

int round down automatically.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜