C PROGRAMMING- Help- how to use the round( ) function and round a float to the nearest hundredth?
@confluxepic @maddiegirl @e.mccormick Please help :)
How do I use the round( ) function in the math.h library to round a float to the nearest hundredth? I want to avoid float imprecision, that's why.
@maddiegirl you there...???
@Whitemonsterbunny17
Maybe @iambatman can help? I don't know this stuff, sorry.
http://www.cplusplus.com/reference/cmath/round/ I do not see it taking any arguments for precision, so the only thing I can think if is to multiply by 100, round, then divide by 100, or use a different function.
Another suggestion is: floor(x*100+0.5)/100; That will add a half to the lowest value then round it down. If you are at .5 or higher on the last digit, post multiplication, it will round up. For .4 to .0 it will round down.
@e.mccormick Thanks for the help.
Join our real-time social learning platform and learn together with your friends!