How to round down to nearest integer in MySQL?

前端 未结 7 1188
自闭症患者
自闭症患者 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:50

    Use FLOOR(), if you want to round your decimal to the lower integer. Examples:

    FLOOR(1.9) => 1
    FLOOR(1.1) => 1
    

    Use ROUND(), if you want to round your decimal to the nearest integer. Examples:

    ROUND(1.9) => 2
    ROUND(1.1) => 1
    

    Use CEIL(), if you want to round your decimal to the upper integer. Examples:

    CEIL(1.9) => 2
    CEIL(1.1) => 2
    

提交回复
热议问题