|
-
Apr 26th, 2002, 09:28 AM
#1
Thread Starter
Addicted Member
Rounding......
What header file and function will let me round in C++, thanks a bunch!
-
Apr 26th, 2002, 09:50 AM
#2
None, here is keda's round function:
inline int round(const double d)
{ return (int)(d + 0.5); }
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 26th, 2002, 10:30 AM
#3
This rounds as well
Code:
sprintf(tmp,"%5.2f",mydouble);
mydouble=ecvt(tmp);
the .2 part sets the number of digits after the decimal - and it actually rounds up.
-
Apr 26th, 2002, 10:40 AM
#4
more gernalized rounding function
a more general rounding function
Code:
#include <stdio.h>
double round(double p, int placesbefore,int placesafter){
char tmp[20];
sprintf(tmp,"%*.*f",placesbefore,placesafter,p);
return ecvt(tmp);
}
usage: mydouble = round(mydouble,5,2);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|