Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rounding all numbers in program

Status
Not open for further replies.

Maurader

Technical User
May 8, 2002
59
CA
I have a program where I need to round almost every number to 6 decimal places. If i create a function to do this, the code gets very messy. Is there an alternate method?
 
I know you can manipulate output precision using std::setprecision( int ) found in iomanip if that helps.

You can also calculate it like this:

double yourNumber,
numberAfterRounding,
precision = 6;

numberAfterRounding =
floor( yourNumber * pow( 10, precision ) + .5 )
/ pow( 10, precision );


Note: include cmath.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top