How to round down to nearest integer in MySQL?

前端 未结 7 1194
自闭症患者
自闭症患者 2020-12-24 04:26

How would I round down to the nearest integer in MySQL?

Example: 12345.7344 rounds to 12345

mysql\'s round() function rounds up.

7条回答
  •  爱一瞬间的悲伤
    2020-12-24 04:53

    SUBSTR will be better than FLOOR in some cases because FLOOR has a "bug" as follow:

    SELECT 25 * 9.54 + 0.5 -> 239.00
    
    SELECT FLOOR(25 * 9.54 + 0.5) -> 238  (oops!)
    
    SELECT SUBSTR((25*9.54+0.5),1,LOCATE('.',(25*9.54+0.5)) - 1) -> 239
    

提交回复
热议问题