Click here to Skip to main content
15,917,565 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to round a double value Pin
King_of_Queens8-Sep-03 22:55
King_of_Queens8-Sep-03 22:55 
GeneralRe: How to round a double value Pin
Dangleberry8-Sep-03 23:14
sussDangleberry8-Sep-03 23:14 
GeneralRe: How to round a double value Pin
vcplusplus9-Sep-03 1:58
vcplusplus9-Sep-03 1:58 
GeneralRe: How to round a double value Pin
Dangleberry9-Sep-03 2:50
sussDangleberry9-Sep-03 2:50 
GeneralRe: How to round a double value Pin
vcplusplus9-Sep-03 3:20
vcplusplus9-Sep-03 3:20 
GeneralRe: How to round a double value Pin
QuiJohn9-Sep-03 3:20
QuiJohn9-Sep-03 3:20 
AnswerRe: How to round a double value Pin
David Crow9-Sep-03 2:47
David Crow9-Sep-03 2:47 
GeneralRe: How to round a double value Pin
Dangleberry9-Sep-03 3:14
sussDangleberry9-Sep-03 3:14 
Now I know what I'm doing, I'd do it like this :

//could make it a variable parameter so you don't have to keep supplying
//it with a param when you just want a standard round.
double rounddouble(double val, int fig=0)
{
//Avoid division by zero by checking fig for zero
if(fig != 0)
{
//get the multiply divide factor
double sigfig = pow(10, (double)fig);

//multiply the figure by 10pow to get the pos to chop the end off
val *= sigfig;

//add 0.5 before rounding so we round up or down
val += 0.5;

//adding 0.5 affects round down value in effect, rounding up or down.
val = floor(val);

//return the decimal to original value with chopped off rounded crap
val /= sigfig;
}
else
{
//just round the figure without an offset
val += 0.5;
val = floor(val);
}

//finally return the value
return val;
}

Hope this helps. This will return the correct rounded double value based on however many significant fig's you specify.

Alan.;P
AnswerRe: How to round a double value Pin
ohadp9-Sep-03 3:28
ohadp9-Sep-03 3:28 
QuestionDCOM -SOAP transparent proxy exists ? Pin
vgrigor8-Sep-03 22:03
vgrigor8-Sep-03 22:03 
GeneralCEdit , Numbers only Pin
KKR8-Sep-03 21:51
KKR8-Sep-03 21:51 
GeneralRe: CEdit , Numbers only Pin
Cedric Moonen8-Sep-03 22:59
Cedric Moonen8-Sep-03 22:59 
GeneralRe: CEdit , Numbers only Pin
KKR8-Sep-03 23:07
KKR8-Sep-03 23:07 
GeneralRe: CEdit , Numbers only Pin
David Crow9-Sep-03 2:26
David Crow9-Sep-03 2:26 
GeneralProblem with printing from printpreview (View class) Pin
Fahr8-Sep-03 21:49
Fahr8-Sep-03 21:49 
Generalfast conversion double / float / int etc. vectors Pin
peterchen8-Sep-03 21:33
peterchen8-Sep-03 21:33 
Generalproblems with afx.h in a dll Pin
villalbaja8-Sep-03 21:32
villalbaja8-Sep-03 21:32 
Generalcompiling at the command line with VC++ 6 Pin
Jerome Conus8-Sep-03 19:48
Jerome Conus8-Sep-03 19:48 
GeneralRe: compiling at the command line with VC++ 6 Pin
Taka Muraoka8-Sep-03 20:39
Taka Muraoka8-Sep-03 20:39 
GeneralRe: compiling at the command line with VC++ 6 Pin
Jerome Conus9-Sep-03 3:21
Jerome Conus9-Sep-03 3:21 
GeneralRe: compiling at the command line with VC++ 6 Pin
Taka Muraoka9-Sep-03 3:34
Taka Muraoka9-Sep-03 3:34 
Generaldialog scroll bars!!! Pin
Marissa1828-Sep-03 19:39
Marissa1828-Sep-03 19:39 
GeneralRe: dialog scroll bars!!! Pin
armentage9-Sep-03 3:53
armentage9-Sep-03 3:53 
GeneralIP Packet Filtering Pin
SatyaDY8-Sep-03 19:23
SatyaDY8-Sep-03 19:23 
GeneralRe: IP Packet Filtering Pin
geo_m9-Sep-03 7:19
geo_m9-Sep-03 7:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.