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. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>