最新消息:

DB2四舍五入详解

SQL 观测者 1953浏览

四舍五入,保留整数:
SELECT round(3.14) FROM SYSIBM.DUAL;
结果:3.00

SELECT cast(round(3.14) AS INT) FROM SYSIBM.DUAL;
结果:3

四舍五入,保留n位小数:
SELECT round(3.14555,2) FROM SYSIBM.DUAL;
结果:3.15000

SELECT cast(round(3.14555,2) AS DOUBLE) FROM SYSIBM.DUAL;
结果:3.15

四舍五入,保留2位小数(避免导出CSV文件后显示为科学计数的问题):
SELECT cast(tm_value AS DECIMAL(15,2)) AS tm_value FROM TABNAME

转载请注明:观测者 » DB2四舍五入详解