Go Down

Topic: Problem with dividing two integers (Read 515 times) previous topic - next topic


Try this example to see what is going on
Code: [Select]

int iA = 123;
int iB = 456;

float fA = 123;
float fB = 456;

void setup()


void loop() {}
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.


Thank you UKHeliBob for making that "easy to learn" example. I got it working:)

Nick Gammon

Nick Gammon:
I can see on a lcd what the values are so it is easy to check if i get the same as on a calculator

Yes, but that doesn't answer my question. What values did you see and what values did you get on the calculator?

That's like saying "I got a sock out of my sock drawer and it wasn't the colour I expected."

Right. What colour did you get, and what colour did you expect to get?


Sorry about that..

I expected to get 4.4 when Points =88 and elapsedTime =20.00
instead i got -1

Nick Gammon

I see. I can't reproduce that:

Code: [Select]

void setup ()
  Serial.begin (115200);
  int Points = 88;
  long elapsedTime = 20;
  Serial.println (Points / elapsedTime);
  }  // end of setup

void loop () { }


Code: [Select]


Go Up