用法
trunc (numeric) →numeric
trunc (double precision) →double precision
trunc (numeric,numeric) →numeric
trunc() 有两个变体
- 一个单参数版本,用于将提供的值向零截断
- 一个双参数版本,用于将提供的值截断到指定的十进制位数
变更历史
- PostgreSQL 6.5
- 添加于 (commit 0e9d75c6)
示例
trunc() 的基本用法示例
postgres=# SELECT trunc(3.14);
trunc
-------
3
(1 row)
postgres=# SELECT trunc(-3.14);
trunc
-------
-3
(1 row)
双参数形式将数字截断到指定的十进制位数
postgres=# SELECT trunc(3.1415926, 2); trunc ------- 3.14 (1 row)
参考资料
- PostgreSQL 文档: 数学函数
