MySQL round half even emulation

I needed to emulate php’s PHP_ROUND_HALF_EVEN behaviour in mysql and did this:

SELECT IF(MOD(col,2)=1.5), FLOOR(col), ROUND(col))

Where col is a float value.

Edit: It seems as mysql’s ROUND() function does this per default. I should have read TFM.

Leave a Reply

Your email address will not be published.