Should I use roundf that is for float input and returns a float value? the function round seems to work equally well. Any views on this?
roundf
and other functions in the "round" family should be used wherever a float or double must be rounded, that includes both input (before any calculation is performed using it) or output (values that are the result of some calculation).
Beside that I'm not exactly sure what you're asking, you may want to check the man page for the "round" family here or with man round
in the terminal.
Edit, I'm not sure if I was clear enough; roundf
and round
both do the exact same thing, round a variable, the difference however, is that roundf
returns a float, whereas round
returns a double. A double is just a "float" of 8 bytes instead of 4, therefore a double is even more precise than a float. Ultimately it doesn't matter which you decide to use, since 4 more bytes is hardly anything.
Good luck!
-
Thanks for your help, I was not sure what was going to happen if I used the construction float value = round( valueChangefloat *100.) Will it try to store a double in the float value output? After reading the man pages I used roundf and i worked. – Pål Ingsøy Oct 24 '16 at 22:56
-
Hmm, that's actually a great question. While I cannot find any answers online, i would assume however, that using round() on a
float
casts the return value back to afloat
before finally putting it inside the variable. – kluvin Oct 25 '16 at 6:01