1

I want to take the value from my slider and without rounding up, crop the decimals. So if I have a float value of 10.973. I want it in an integer as 10. I dont use negative values but if the slider value is between 0 and 1 id rather it round up. How would i make a statement doing the following?

4

3 回答 3

1

只需一个简单的整数转换即可。

int intVal = (int)floatVal;
于 2013-09-16T21:55:43.143 回答
1

你应该使用:

f = (int)floorf(x);

floorf然而将四舍五入到较小的整数,因此-2.79将导致-3.

于 2013-09-16T21:50:02.587 回答
0

一个简单的整数转换应该可以:

int i = int(f)

如果 f 是 10.973,我将是 10。如果 f 是 -10.973,我将是 -10。强制转换为 int 只会截断小数部分。

于 2013-09-16T21:58:07.327 回答