How to round down to nearest integer in MySQL?

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

    if you need decimals can use this

    DECLARE @Num NUMERIC(18, 7) = 19.1471985
    SELECT FLOOR(@Num * 10000) / 10000
    

    Output: 19.147100 Clear: 985 Add: 00

    OR use this:

    SELECT SUBSTRING(CONVERT(VARCHAR, @Num), 1, CHARINDEX('.', @Num) + 4)
    

    Output: 19.1471 Clear: 985

提交回复
热议问题