PostgreSQL/Math Functions/round

Материал из SQL эксперт
Перейти к: навигация, поиск

round(x): Returns x rounded to the nearest whole integer

postgres=#
postgres=# -- round(x): Returns x rounded to the nearest whole integer
postgres=#
postgres=# SELECT round(1.0) AS one,
postgres-#        round(1.1) AS "one point one",
postgres-#        round(1.5) AS "one point five",
postgres-#        round(1.8) AS "one point eight";
 one | one point one | one point five | one point eight
-----+---------------+----------------+-----------------
   1 |             1 |              2 |               2
(1 row)
postgres=#



round(x, s): Returns the value of x, optionally rounded to s decimal places

postgres=#
postgres=# -- round(x, s): Returns the value of x, optionally rounded to s decimal places
postgres=# SELECT round(1.4949, 1) AS one_digit_scale,
postgres-#        round(1.4949, 3) AS three_digit_scale,
postgres-#        round(1.4949, 10) AS ten_digit_scale,
postgres-#        round(1.4949, 0) AS rounded;
 one_digit_scale | three_digit_scale | ten_digit_scale | rounded
-----------------+-------------------+-----------------+---------
             1.5 |             1.495 |    1.4949000000 |       1
(1 row)
postgres=#



SELECT round(4, 4)

postgres=# SELECT round(4, 4);
 round
--------
 4.0000
(1 row)
postgres=#