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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rounding a double 1

Status
Not open for further replies.

PaolaS

Programmer
Aug 23, 2001
8
0
0
ES
How can I round a double number?
Ex.,
double x = 3.124578

Result 3.1246
 
One method would be:

#include <math.h>

int decimal, sign;
double dTest=1.234567;
const int nDecimals=3;

dTest=atof(_fcvt(dTest, nDecimals,&decimal, &sign))/pow(10,nDecimals);

But, I am sure there must be another simpler one... :)

HTH, s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top