Click here to Skip to main content
15,887,746 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: how to integrate WPF window designs in vc++ win32/mfc environment? Pin
Richard MacCutchan24-Feb-11 22:55
mveRichard MacCutchan24-Feb-11 22:55 
QuestionConvert from Double to Integer w/o Rounding in C++ Pin
User 741604624-Feb-11 12:06
User 741604624-Feb-11 12:06 
AnswerRe: Convert from Double to Integer w/o Rounding in C++ Pin
Luc Pattyn24-Feb-11 12:30
sitebuilderLuc Pattyn24-Feb-11 12:30 
GeneralRe: Convert from Double to Integer w/o Rounding in C++ Pin
User 741604624-Feb-11 13:31
User 741604624-Feb-11 13:31 
QuestionRe: Convert from Double to Integer w/o Rounding in C++ Pin
Luc Pattyn24-Feb-11 13:42
sitebuilderLuc Pattyn24-Feb-11 13:42 
AnswerRe: Convert from Double to Integer w/o Rounding in C++ Pin
«_Superman_»24-Feb-11 18:51
professional«_Superman_»24-Feb-11 18:51 
AnswerRe: Convert from Double to Integer w/o Rounding in C++ Pin
Bernhard Hiller24-Feb-11 20:56
Bernhard Hiller24-Feb-11 20:56 
AnswerRe: Convert from Double to Integer w/o Rounding in C++ Pin
Andrew Brock24-Feb-11 22:20
Andrew Brock24-Feb-11 22:20 
I thought it was a standard thing, but when I do int(1.732) I get 1 and int(-1.732) I get -1.
A look at the disassembly shows that a function from the CRT (_ftol2 in my case) is used, so it could be implementation specific.

If this is the case then you should use something like floor/ceil as Bernhard Hiller suggested.
This function will result in the behaviour described above, where numbers round towards 0.
It includes epsilon rounding to account for epsilon errors.
In some cases 3 = 2.99999999999 (or something similar) due to rounding errors in previous operations.
See http://en.wikipedia.org/wiki/Double_precision[^] for more details
int DoubleToInt(double nDouble) {
	if (nDouble >= 0) {
		retrun (int)floor(nDouble + DBL_EPSILON);
	} else {
		retrun (int)ceil(nDouble - DBL_EPSILON);
	}
}

GeneralRe: Convert from Double to Integer w/o Rounding in C++ Pin
User 741604625-Feb-11 2:44
User 741604625-Feb-11 2:44 
QuestionHow can I retrieve handlw of dropdown list box ? Pin
_Flaviu24-Feb-11 5:20
_Flaviu24-Feb-11 5:20 
AnswerRe: How can I retrieve handlw of dropdown list box ? Pin
Hans Dietrich24-Feb-11 5:31
mentorHans Dietrich24-Feb-11 5:31 
GeneralRe: How can I retrieve handlw of dropdown list box ? Pin
_Flaviu24-Feb-11 7:02
_Flaviu24-Feb-11 7:02 
AnswerRe: How can I retrieve handlw of dropdown list box ? Pin
Code-o-mat24-Feb-11 8:33
Code-o-mat24-Feb-11 8:33 
GeneralRe: How can I retrieve handlw of dropdown list box ? Pin
_Flaviu24-Feb-11 9:52
_Flaviu24-Feb-11 9:52 
GeneralRe: How can I retrieve handlw of dropdown list box ? Pin
Code-o-mat24-Feb-11 9:54
Code-o-mat24-Feb-11 9:54 
GeneralRe: How can I retrieve handle of dropdown list box ? Pin
_Flaviu24-Feb-11 22:03
_Flaviu24-Feb-11 22:03 
GeneralRe: How can I retrieve handle of dropdown list box ? Pin
Code-o-mat24-Feb-11 22:06
Code-o-mat24-Feb-11 22:06 
GeneralRe: How can I retrieve handle of dropdown list box ? Pin
_Flaviu26-Feb-11 22:09
_Flaviu26-Feb-11 22:09 
QuestionDisabling Keypress on MessageBox Pin
si_6924-Feb-11 0:45
si_6924-Feb-11 0:45 
AnswerRe: Disabling Keypress on MessageBox PinPopular
Andrew Brock24-Feb-11 1:13
Andrew Brock24-Feb-11 1:13 
AnswerRe: Disabling Keypress on MessageBox Pin
David Crow24-Feb-11 2:57
David Crow24-Feb-11 2:57 
QuestionHow to Call C# DLL in VC++ win32? Pin
mathivanaan24-Feb-11 0:35
mathivanaan24-Feb-11 0:35 
AnswerRe: How to Call C# DLL in VC++ win32? Pin
Richard MacCutchan24-Feb-11 0:52
mveRichard MacCutchan24-Feb-11 0:52 
AnswerRe: How to Call C# DLL in VC++ win32? Pin
Cool_Dev24-Feb-11 1:15
Cool_Dev24-Feb-11 1:15 
AnswerRe: How to Call C# DLL in VC++ win32? Pin
Bernhard Hiller24-Feb-11 4:07
Bernhard Hiller24-Feb-11 4:07 

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.