Click here to Skip to main content
15,861,125 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: App Launch Crash Pin
Andrew Brock19-Jan-11 3:52
Andrew Brock19-Jan-11 3:52 
AnswerRe: App Launch Crash Pin
KingsGambit19-Jan-11 0:39
KingsGambit19-Jan-11 0:39 
GeneralRe: App Launch Crash Pin
Andrew Brock19-Jan-11 0:56
Andrew Brock19-Jan-11 0:56 
AnswerRe: App Launch Crash Pin
CPallini19-Jan-11 0:50
mveCPallini19-Jan-11 0:50 
AnswerRe: App Launch Crash Pin
Abhi Lahare20-Jan-11 9:02
Abhi Lahare20-Jan-11 9:02 
QuestionHow to append string with ". Pin
raju_shiva18-Jan-11 23:32
raju_shiva18-Jan-11 23:32 
AnswerRe: How to append string with ". Pin
Emilio Garavaglia18-Jan-11 23:40
Emilio Garavaglia18-Jan-11 23:40 
QuestionRounding double to a provided decimal place Pin
PankajB18-Jan-11 23:21
PankajB18-Jan-11 23:21 
Hi All.

A very simple question, but so far not able to find any concrete solution.
I just want to round a decimal value to a provided decimal place.

I have found few functions to do the same, but they also fail for some double values...like...

double Round1(double dbVal, int nPlaces)
{
    const double dbShift = pow(10.0, nPlaces);
    return  floor(dbVal * dbShift + 0.5) / dbShift; 
}

double Round2(double value,int pos)
{
    double  returnValue;
    double tens = exp(pos*log(10.0));
    if((value - floor(value*tens)/tens)*tens >= 0.5)
          returnValue = ceil(value*tens)/tens 
    else
          returnValue = floor(value*tens)/tens;

    return returnValue;
}


Both of above function fails in case the double value is
10430.889999999999
464.45999999999998
3294.5100000000002


Please suggest.

Thanks
PanB
AnswerRe: Rounding double to a provided decimal place Pin
T210218-Jan-11 23:41
T210218-Jan-11 23:41 
AnswerRe: Rounding double to a provided decimal place Pin
_AnsHUMAN_ 18-Jan-11 23:42
_AnsHUMAN_ 18-Jan-11 23:42 
GeneralRe: Rounding double to a provided decimal place Pin
PankajB18-Jan-11 23:49
PankajB18-Jan-11 23:49 
GeneralRe: Rounding double to a provided decimal place Pin
Cedric Moonen19-Jan-11 0:07
Cedric Moonen19-Jan-11 0:07 
AnswerRe: Rounding double to a provided decimal place Pin
User 742933819-Jan-11 0:00
professionalUser 742933819-Jan-11 0:00 
AnswerRe: Rounding double to a provided decimal place Pin
Cedric Moonen19-Jan-11 0:01
Cedric Moonen19-Jan-11 0:01 
AnswerRe: Rounding double to a provided decimal place Pin
Richard MacCutchan19-Jan-11 3:11
mveRichard MacCutchan19-Jan-11 3:11 
Questionx86 and x64 code performance in 64 bit w7 Pin
Chesnokov Yuriy18-Jan-11 22:24
professionalChesnokov Yuriy18-Jan-11 22:24 
AnswerRe: x86 and x64 code performance in 64 bit w7 Pin
Emilio Garavaglia18-Jan-11 22:47
Emilio Garavaglia18-Jan-11 22:47 
GeneralRe: x86 and x64 code performance in 64 bit w7 Pin
Chesnokov Yuriy18-Jan-11 23:57
professionalChesnokov Yuriy18-Jan-11 23:57 
GeneralRe: x86 and x64 code performance in 64 bit w7 Pin
Emilio Garavaglia19-Jan-11 2:48
Emilio Garavaglia19-Jan-11 2:48 
GeneralRe: x86 and x64 code performance in 64 bit w7 Pin
Chesnokov Yuriy19-Jan-11 3:04
professionalChesnokov Yuriy19-Jan-11 3:04 
AnswerRe: x86 and x64 code performance in 64 bit w7 Pin
Andrew Brock18-Jan-11 23:16
Andrew Brock18-Jan-11 23:16 
GeneralRe: x86 and x64 code performance in 64 bit w7 Pin
Chesnokov Yuriy19-Jan-11 0:01
professionalChesnokov Yuriy19-Jan-11 0:01 
QuestionRe: x86 and x64 code performance in 64 bit w7 Pin
CPallini18-Jan-11 23:43
mveCPallini18-Jan-11 23:43 
AnswerRe: x86 and x64 code performance in 64 bit w7 Pin
Chesnokov Yuriy19-Jan-11 0:04
professionalChesnokov Yuriy19-Jan-11 0:04 
GeneralRe: x86 and x64 code performance in 64 bit w7 Pin
CPallini19-Jan-11 0:15
mveCPallini19-Jan-11 0:15 

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.