On 9 Jul 2006 21:32:18 -0700,
cl***@yahoo.de wrote:
>can please someone explain why i get the message-box?
im damn shure 500 divided by 300 doesnt equal to zero ;-\
__________________________________
unsigned short uiNumbers = 500;
unsigned float ufFactor = 300.0;
ufFactor = ufFactor / uiNumbers;
if (ufFactor == 0) AfxMessageBox("0");
unsigned float?
Anyway, it seems thta ufFactor (which should have the value 300.0/500)
is converted to int (thus, rounded to 0) before being compared.
Try :
if (ufFactor == 0.0) AfxMessageBox("0");
This is an tricky comparison, as comparison with doubles (and floats)
is subject to lots of problems due to rounding. You should take a look
at this list, siblig list comp.lang.c++.moderated and cousin lists
comp.lang.c and comp.lang.c.moderated about floating point comparisons
Regards,
Zara