PDA

View Full Version : Rounding function


moldrat
02-21-2006, 09:24 AM
How would I go about making a function to round a number? Ie, turn 4.34532548 to 4.35 or 4.3453 in C++? Is there already a function in maybe a math header or something? I know how to round to the nearest one but I want to be able to get the nearest tenth or hundredth. I dunno if any of you can help but thanks anyways

Ender
02-21-2006, 05:09 PM
This smells like a homework assignment. I will tell you a few things though: there are many ways to do it, there probably are standard library calls or non-standard libraries that do this, AND... hint: use mods.

oracleguy
02-21-2006, 07:32 PM
Well think about it this way, how would you decide what the number would be if you rounded that first number to the hundrendths? And then just write a function that does whatever you do in your head.