Click here to Skip to main content
15,914,066 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralProblem with double Pin
User 58385228-Dec-03 13:47
User 58385228-Dec-03 13:47 
Hello,
I have the following simple code and I cant understand the results I am seeing

Note. This is a big hack in an old peice of code. It would not be like this if I had my way Frown | :(

void SomeFn(void)
{
//these are not hard coded they come from another API in string form
CString result = CalcMargin("0.7033", "0.7000");
}

CString CalcMargin(LPCTSTR exeRate, LPCTSTR rate)
{
double dExeRate, dRate, dMargin;

dExeRate = atof(exeRate);
dRate = atof(rate);

dMargin = dExeRate - dRate;

result.Format("%f", dMargin);

return result;
}


The returned value is "0.003300" and I wondered why i see the trailing zeros. It turnes out that the result of the subtraction is 0.0033000000000001

Can anyone tell me why?
Thanks
GeneralRe: Problem with double Pin
kjessee28-Dec-03 14:04
kjessee28-Dec-03 14:04 
GeneralRe: Problem with double Pin
Michael Dunn28-Dec-03 17:58
sitebuilderMichael Dunn28-Dec-03 17:58 
GeneralRe: Problem with double Pin
User 58385228-Dec-03 18:12
User 58385228-Dec-03 18:12 
GeneralRe: Problem with double Pin
PJ Arends28-Dec-03 18:43
professionalPJ Arends28-Dec-03 18:43 
GeneralRe: Problem with double Pin
User 58385229-Dec-03 17:57
User 58385229-Dec-03 17:57 
GeneralNeed help with ODBC database/Edit box Pin
Zombie_Inc28-Dec-03 12:15
Zombie_Inc28-Dec-03 12:15 
GeneralRe: Need help with ODBC database/Edit box Pin
PJ Arends28-Dec-03 15:24
professionalPJ Arends28-Dec-03 15:24 
GeneralSimple Problem. How can I show an "Open file" dialog in a dialog-based App from MFC AppWizard Pin
andreir2328-Dec-03 12:07
andreir2328-Dec-03 12:07 
GeneralRe: Simple Problem. How can I show an "Open file" dialog in a dialog-based App from MFC AppWizard Pin
User 665828-Dec-03 12:52
User 665828-Dec-03 12:52 
GeneralRe: Simple Problem. How can I show an "Open file" dialog in a dialog-based App from MFC AppWizard Pin
andreir2328-Dec-03 15:20
andreir2328-Dec-03 15:20 
GeneralDialog problem Pin
Selevercin28-Dec-03 12:06
Selevercin28-Dec-03 12:06 
GeneralRe: Dialog problem Pin
User 58385228-Dec-03 14:08
User 58385228-Dec-03 14:08 
GeneralRe: Dialog problem Pin
Selevercin28-Dec-03 15:27
Selevercin28-Dec-03 15:27 
GeneralRe: Dialog problem Pin
User 58385228-Dec-03 15:36
User 58385228-Dec-03 15:36 
Generalcustom appwizard and images (Visual Studio 6.0) Pin
juthus28-Dec-03 10:32
juthus28-Dec-03 10:32 
GeneralCTreeCtrl and GetItem Problem Pin
User 1278228-Dec-03 9:33
User 1278228-Dec-03 9:33 
GeneralRe: CTreeCtrl and GetItem Problem Pin
PJ Arends28-Dec-03 15:53
professionalPJ Arends28-Dec-03 15:53 
GeneralRe: CTreeCtrl and GetItem Problem Pin
User 1278230-Dec-03 10:10
User 1278230-Dec-03 10:10 
Questionhow to add two projects Pin
auur28-Dec-03 8:01
auur28-Dec-03 8:01 
AnswerRe: how to add two projects Pin
Shanmuga Sundar28-Dec-03 16:47
Shanmuga Sundar28-Dec-03 16:47 
GeneralDisabling F1 Pin
Dominik Reichl28-Dec-03 7:41
Dominik Reichl28-Dec-03 7:41 
GeneralRe: Disabling F1 Pin
PJ Arends28-Dec-03 15:01
professionalPJ Arends28-Dec-03 15:01 
GeneralRe: Disabling F1 Pin
Dominik Reichl28-Dec-03 21:52
Dominik Reichl28-Dec-03 21:52 
GeneralRe: Disabling F1 Pin
Dominik Reichl28-Dec-03 21:53
Dominik Reichl28-Dec-03 21:53 

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.