Is there any way to round numbers in C?
I do not want to use ceil and floor. Is there any other alternative?
I came across this code snippet when I Googled f
You may be able to use fesetround() in fenv.h (introduced in C99). The possible arguments are the macros FE_DOWNWARD, FE_TONEAREST, FE_TOWARDZERO, and FE_UPWARD but note that not all of them are necessarily defined - only the ones supported by the platform/implementation are. Then you can use the various round, rint and nearbyint functions in math.h (also C99). This way you can set the desired rounding behaviour once and call the same function regardless of whether or not the value is positive or negative.
(With e.g. lround you usually need not even set the rounding direction for normal use to usually get what you want.)