"how exactly work round function in postgresql?" Code Answer

6

This page in the documentation indicates the differences in rounding between different data types:

The types decimal and numeric are equivalent. Both types are part of the SQL standard.

When rounding values, the numeric type rounds ties away from zero, while (on most machines) the real and double precision types round ties to the nearest even number. For example:

SELECT x,
    round(x::numeric) AS num_round,
    round(x::double precision) AS dbl_round
FROM generate_series(-3.5, 3.5, 1) as x;

  x   | num_round | dbl_round
------+-----------+-----------
 -3.5 |        -4 |        -4
 -2.5 |        -3 |        -2
 -1.5 |        -2 |        -2
 -0.5 |        -1 |        -0
  0.5 |         1 |         0
  1.5 |         2 |         2
  2.5 |         3 |         2
  3.5 |         4 |         4
(8 rows)

There was some discussion on the pgsql-hackers mailing list about the changes here.

By GodD on January 22 2022

Answers related to “how exactly work round function in postgresql?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.