Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (davidusa):

C PROGRAMMING- Help- how to use the round( ) function and round a float to the nearest hundredth?

OpenStudy (davidusa):

@confluxepic @maddiegirl @e.mccormick Please help :)

OpenStudy (davidusa):

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.

OpenStudy (davidusa):

@maddiegirl you there...???

OpenStudy (davidusa):

@Whitemonsterbunny17

whitemonsterbunny17 (whitemonsterbunny17):

Maybe @iambatman can help? I don't know this stuff, sorry.

OpenStudy (e.mccormick):

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.

OpenStudy (e.mccormick):

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.

OpenStudy (davidusa):

@e.mccormick Thanks for the help.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!