我需要将数字四舍五入并保持(.5),例如:
如果数字=(9115.7),则为(9116)
如果数字=(9115.5),则为(9115.5)
如果数字=(9115.3),则为(9115)
您可以使用case表达式重写自己的舍入逻辑:
CREATE TABLE t AS SELECT 9115.7 AS col FROM dual UNION ALL SELECT 9115.5 AS col FROM dual UNION ALL SELECT 9115.3 AS col FROM dual; SELECT col, CASE WHEN MOD(ABS(col),1) = 0.5 THEN col ELSE ROUND(col) END FROM t;
db <> fiddle演示
输出:
+---------+---------+ | COL | ROUNDED | +---------+---------+ | 9115.7 | 9116 | | 9115.5 | 9115.5 | | 9115.3 | 9115 | +---------+---------+