trunc()

一个用于截断数字的函数

trunc() 是一个用于截断数字的系统函数,可以截断到整数或指定的十进制位数。

trunc()PostgreSQL 6.5 中添加。

有关截断表,请参阅 SQL 命令 TRUNCATE

用法

trunc ( numeric ) → numeric
trunc ( double precision ) → double precision
trunc ( numeric , numeric ) → numeric

trunc() 有两个变体

  • 一个单参数版本,用于将提供的值向零截断
  • 一个双参数版本,用于将提供的值截断到指定的十进制位数

变更历史

示例

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)

分类

系统函数

另请参阅

trim_scale(), scale(), min_scale(),

反馈

提交关于“trunc()”的任何评论、建议或更正请点击 这里