Format retuening a negative value
-
Hi all, I am converting a double value to CString using format but it is giving negative value,
double val3 = val2/(1024*1024);
CString test_size;
test_size.Format(_T("%d"),val3);
AfxMessageBox(test_size);Can anybody please tell me what is the error. i am coding in vc2008
-
Hi all, I am converting a double value to CString using format but it is giving negative value,
double val3 = val2/(1024*1024);
CString test_size;
test_size.Format(_T("%d"),val3);
AfxMessageBox(test_size);Can anybody please tell me what is the error. i am coding in vc2008
What is val2?
It is a crappy thing, but it's life -^ Carlo Pallini
-
What is val2?
It is a crappy thing, but it's life -^ Carlo Pallini
double
double val0 = c*bps;
double val1 = val0*spt;
double val2 = val1*h;
double val3 = val2/(1024*1024); -
Hi all, I am converting a double value to CString using format but it is giving negative value,
double val3 = val2/(1024*1024);
CString test_size;
test_size.Format(_T("%d"),val3);
AfxMessageBox(test_size);Can anybody please tell me what is the error. i am coding in vc2008
Double and integer are represented as a different binary format. You should casting double to integer before passing a parameter. test_size.Format(_T("%d"),(int) val3);
-
What is val2?
It is a crappy thing, but it's life -^ Carlo Pallini
-
double
double val0 = c*bps;
double val1 = val0*spt;
double val2 = val1*h;
double val3 = val2/(1024*1024); -
Hi all, I am converting a double value to CString using format but it is giving negative value,
double val3 = val2/(1024*1024);
CString test_size;
test_size.Format(_T("%d"),val3);
AfxMessageBox(test_size);Can anybody please tell me what is the error. i am coding in vc2008
You are trying tackling with variable of type double variable. If you really wanna to cast the double into integer use casting as :
test_size.Format(_T("%d"),(int) val3);
or use proper format specifier :
test_size.Format(_T("%f"), val3);
-Malli...! :rose:****
-
SnaKeBeD wrote:
For answering ur question please tell what is val2 and y u r using "%d"
My question itself was, what is "val2". May be you wanted to reply to the OP?
It is a crappy thing, but it's life -^ Carlo Pallini
-
Hi all, I am converting a double value to CString using format but it is giving negative value,
double val3 = val2/(1024*1024);
CString test_size;
test_size.Format(_T("%d"),val3);
AfxMessageBox(test_size);Can anybody please tell me what is the error. i am coding in vc2008
VCProgrammer wrote:
Can anybody please tell me what is the error.
Yes: you haven't properly read the documentation about format specification fields, see for instance [^]. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]