What header file and function will let me round in C++, thanks a bunch!
Printable View
What header file and function will let me round in C++, thanks a bunch!
None, here is keda's round function:
inline int round(const double d)
{ return (int)(d + 0.5); }
This rounds as well
the .2 part sets the number of digits after the decimal - and it actually rounds up.Code:sprintf(tmp,"%5.2f",mydouble);
mydouble=ecvt(tmp);
a more general rounding function
usage: mydouble = round(mydouble,5,2);Code:#include <stdio.h>
double round(double p, int placesbefore,int placesafter){
char tmp[20];
sprintf(tmp,"%*.*f",placesbefore,placesafter,p);
return ecvt(tmp);
}