# Arduino calculation returns 0: integer division and float values

> Fix a result that is always 0 or rounded: integers divide without decimals, so use a float and write numbers like 2.0.

Canonical: https://roboticsengineering.in/fix/arduino-integer-division-returns-zero/ | Published: 2026-11-03 | Updated: 2026-11-03

**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 see | Do this |
| --- | --- |
| Result is 0 or 1 only | Integer division. |
| Result wraps to negative | Overflow. Use long. |

## Related

[map() function](https://roboticsengineering.in/fix/arduino-map-function-wrong-range-integer/), [serial monitor shows nothing](https://roboticsengineering.in/fix/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.
