I have a float which I'd like to round up or down to the nearest integer.
For example:
1.4 = 1.0 1.77 = 2.0 1.1 = 1.0
etc...
I'm doing this in Objective C, so I guess I need a standard math function... Would nearbyintf do it?
You can use any of the standard C library math functions defined in math.h. nearbyintf would work, as would roundf or ceilf or floorf, depending on what you want.
Xcode will show you the documentation (UNIX manual page) for these functions if you option-double-click them in the editor.
use
double a = 2.3;
double b = round(a);
You can find round and other math functions in math.h
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With