So i have
float x = x + 0.25;
This float will be called every time a click happens
NSLog(@”%f”,x);
I want the nslog to only return the whole number portion so like this
x return
1.25 1
1.50 1
3.25 3
4.75 4
Any ideas?
Converting to
intwon’t work if the floating-point number is outside the range ofint.Printing with
"%.0f"doesn’t truncate, it rounds, so 4.75 will print as5.If your compiler (more accurately, your runtime library) supports them, the
trunc(),truncf(), andtruncl()functions, declared in<math.h>, do exactly what you want:Those functions are new in C99, so it’s possible your compiler doesn’t support them. C90 does provide a
floor()function; you can use that if you write some special-case code for negative numbers.