# Round odd number down to even number?

Plain and simple, I’d like to know how to round an odd number down to an even number.

The reason being, I need to send a set point value to a thermostat that will only accept even numbers (0,2,4,6,8).
I want to sync my main thermostat with a split system on the same floor. so if the main thermostat is set at 71, I need it to round down to 70, but if it’s 72, it doesn’t change.

Any Ideas guys? I’ve been at google for hours but I am at a complete loss.
I’m thinking something like:

``````var Number SetPointState = SetPoint.state as DecimalType
SetPointState = SetPointState //some sort of math magic here...
``````

Thanks in advance to anyone willing to lend a hand here, I’d really appreciate it.

Try

``````SetpointState = SetpointState - (SetpointState % 2)
``````

I think this should work, as long as SetpointState is an integer.

Thanks so much, I got it working

mod should work. On top of my head, you can also just divide by 2, then cast to int to drop the decimals

sorry, I dint have integer type, fixed it now