Arduino calculation returns 0: integer division and float values

Two integers divided give an integer. 1 / 2 is 0. Make one side a float, for example 1.0 / 2.

What the message means

The compiler uses the types of the numbers, not the type of the variable that receives the answer.

Fix it in this order

  1. Write one number with a decimal point, such as 5.0.
  2. Or cast: (float)a / b.
  3. Store the result in a float variable.
  4. Multiply before dividing when you want to stay in integers, as in a * 100 / b.
  5. Watch for overflow in int, which is 16 bit on an Uno. Use long for big products.

Why it happens

When both numbers are integers, the result is also an integer, and the fraction is thrown away: 1 / 2 is 0. This surprises people when scaling a sensor value.

Make one value a float, for example 1.0 / 2, or cast it: (float)a / b. Do the multiplication first when you need to keep precision with integers.

If you see this, do this

You seeDo this
Result is 0 or 1 onlyInteger division.
Result wraps to negativeOverflow. Use long.

map() function, serial monitor shows nothing.

Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.