 # Simple calculation fails

Hi,

I'm embarassed to post this question here. But I am not able to calculate a common divider / multiplier operation. I'm stuck and I hope that someone can help me. I can't figure out that strange behaviour:

Here some tryouts. Result should be 35,98, or better 36 (%).

first try:

``````Serial.println((2913/8096)*100);
=> results in 0
``````

second try:

``````char t;
float i = (2913/8096)*100;
sprintf(t, "%d", i);

Serial.println(t);
=> results in 0.
``````

third try:

``````char t;
int i = (2913/8096)*100;
itoa((2913/8096)*100, t, 10);

Serial.println(t);
=> results in 0.
``````

I've changed i to be float, int, long. Result is the same.

What am I doing wrong?! This is incredible I cant find my mistake :~

-Florian

`Serial.println((2913L * 100L) /8096L);` ?

Thank you. It works fine.

I've learned something new today :) -> IntegerConstants!

Next step is to learn about float constants.

``````Serial.println((2913.0/8096.0)*100.0);
``````

Will NOT print 0.

mesa: Thank you. It works fine.

I've learned something new today :) -> IntegerConstants!

And hopefully you've learned that dividing an integer by a larger integer will give you zero.