Reputation: 1738
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?
Upvotes: 1
Views: 844
Reputation: 494
A simple cast to integer should do:
int i = int(f)
If f is 10.973 i will be 10. If f is -10.973, i will be -10. A cast to int will simply truncate the decimal part.
Upvotes: 0
Reputation: 153
Just a simple integer cast would work.
int intVal = (int)floatVal;
Upvotes: 1
Reputation: 476503
You should use:
f = (int)floorf(x);
floorf
however will round to the lower integer so -2.79
will result in -3
.
Upvotes: 1