Postgrel 取整函数、四舍五入函数和保留几位小数
地址: https://postgres.fun/20140508101444.html
四舍五入函数
Function | Return Type | Description |
---|---|---|
round(dp or numeric) | (same as input) | round to nearest integer |
round(v numeric, s int) | numeric | round to s decimal places |
francs=> select round(10.2);
round
-------
10
(1 row)
francs=> select round(10.9);
round
-------
11
(1 row)
francs=> select 10.1/3;
?column?
--------------------
3.3666666666666667
(1 row)
francs=> select round(10.1/3);
round
-------
3
(1 row)
francs=> select round(10.1/3,2);
round
-------
3.37
(1 row)
取整函数
Function | Return Type | Description |
---|---|---|
ceil(dp or numeric) | (same as input) | smallest integer not less than argument |
floor(dp or numeric) | (same as input) | largest integer not greater than argument |
返回大于或等于给出数字的最小整数
francs=> select ceil(3.36);
ceil
------
4
(1 row)
francs=> select ceil(-3.36);
ceil
------
-3
(1 row)
返回小于或等于给出数字的最大整数
francs=> select floor(3.36);
floor
-------
3
(1 row)
francs=> select floor(-3.36);
floor
-------
-4
(1 row)
备注:如果没记错的话,这几个函数在 oracle 当中是通用的。