Dividing an integer by 2,does it round the number?

Let's say you have an integer of 321, and you want to divide it by 2.
That would make 160,5.
Since integers don't have floating point values, will it just round the number?

The answer will be truncated instead of rounded. Integer 321 divided by integer 2 = integer 160.

No rounding built in, it just discards the leftovers.

I had to write a small function for a temp sensor project because 24.8°C is NOT 24°C when it comes to deciding to kick in AC or not.

Easier at the time to make a simple function - know better now.

BRUTUS, why didnt you just wait for it to be 25 C ?

I actually wanted to catch it when it was 24.5°C. Dealing with AC turned out to be a royal PITA.

The unit we had roughly cooled 0.5°C per hour, as long as outside temp was lower than about 27°.

Inside, a fan tried to exchange warmer upstairs air with cooler basement air. Once it reaches the limit of what it can do, and the AC can still make a difference, we had a critical cross point.

When I had the system set to 24, it was a bit soon, and the AC ended up running what seemed like all day.

At 25, it seemed like the AC never caught up, and it was only comfortable about 6' around the unit.

So... I wanted 24.5

In the end it was all scrapped, and am working on something better now. Fuzzy logic FTW (hopefully)

It would make sense if it would round 10,5 to 11, and 10,3 to 10. right?

It would make sense

Yes but it is a computer, it is not how it works.

The simple answer is just to have your numbers 10 time what they need to be and so work in tenths of a unit instead of units.

If you need rounding, just add one to the value before dividing.

-3 / 4

(-3+1) / 4

-2 / 4

0 != -1

0 / 1

0+1 / 1

1 != 0

@rFree

-3 / 2

(-3+1) / 2

-2 / 2

-1 == -1

0 / 2

0+1 / 2

0 == 0

I assumed that since the question was about division by two, the reader would be sufficiently arithmetically adept to add in the appropriate constant (i.e. half the divisor) when rounding for other values.

-3 / 4

(-3+2) / 4

-1 / 4

0 == 0

0 / 1

0+0 / 1

0 == 0