Lee

Lee

  • NA
  • 8
  • 7.5k

Integers, Floats and Doubles

Mar 26 2011 6:17 AM
Hello,

I'll start with the usual apology for such a basic question, but I can't get my head around this.

Here is my code from the tutorial I am using:





float firstNumber;

float secondNumber;

float floatAnswer;

int integerAnswer;

firstNumber = 10.5F;

secondNumber = 32.5F;

integerAnswer = firstNumber + secondNumber;


MessageBox.Show(integerAnswer.ToString());


This fails because according to the tutorial you cannot store a float variable as an integer.  That's fine.  What I can't get my head around is the fact that the answer to the sum IS an integer.  10.5 + 32.5 = 43. 

43 doesn't have a decimal place so it is an integer, right?  What am I missing?

Can anybody simplify this for me, or should I just give up now lol?

Many Thanks

Lee

Answers (4)