G
GuineaPig
Hello,
I'm (very) new to c++ and I'm having trouble understanding why this doesn't
work. Here's some testcode:
#include <iostream.h>
int main()
{
float test;
unsigned int test2;
test = 1.8;
cout << "\n" << test*100.0 << endl;
test2 = static_cast<unsigned int>(test*100.0);
cout << "\n" << test2 << endl;
}
The strange thing is that the program returns 180 on the first cout (as
expected) but it returns 179 on the second ???
If I make test 1.7, I get 170 on the first and second cout ???
I tried a whole bunch of other values... Sometimes I'm getting what I
expected, sometimes not...
Can anyone explain this to me ?
Tnx in advance,
Tom
I'm (very) new to c++ and I'm having trouble understanding why this doesn't
work. Here's some testcode:
#include <iostream.h>
int main()
{
float test;
unsigned int test2;
test = 1.8;
cout << "\n" << test*100.0 << endl;
test2 = static_cast<unsigned int>(test*100.0);
cout << "\n" << test2 << endl;
}
The strange thing is that the program returns 180 on the first cout (as
expected) but it returns 179 on the second ???
If I make test 1.7, I get 170 on the first and second cout ???
I tried a whole bunch of other values... Sometimes I'm getting what I
expected, sometimes not...
Can anyone explain this to me ?
Tnx in advance,
Tom