0.1 = 0 ???

From: Paul Surgeon (surgptr_at_pop.co.za)
Date: 10/26/03


Date: Sun, 26 Oct 2003 15:17:19 +0200

I cannot figure out how C++ works with data types/conversions.
I have tried two conditional statements :

if ((1 / 10) == 0)
  cout << "Houston we have a problem\n";

double Data = (1 / 10);
if (Data == 0)
  cout << "Houston we have a problem\n";

In both cases the conditional statement resolves as true!
How the *beep* can 0.1 be equal to 0?

What on earth am I doing wrong?

I have never seen this problem in my 4 years of Delphi coding.
What is C++ doing that is so different?

Thanks
Paul



Relevant Pages

  • Re: 0.1 = 0 ???
    ... > I have tried two conditional statements: ... > What on earth am I doing wrong? ... > I have never seen this problem in my 4 years of Delphi coding. ... You are dividing integers and expecting a decimal result. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: 0.1 = 0 ???
    ... > I have tried two conditional statements: ... > What on earth am I doing wrong? ... I know it's drives you crazy and it has driven me crazy on numerous ... occassions too .- LOL ...
    (alt.comp.lang.learn.c-cpp)