mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Add documentation and regression tests concerning rounding of numerics.
Michael Paquier, reviewed by Fabien Coelho
This commit is contained in:
@ -612,6 +612,31 @@ NUMERIC
|
||||
equivalent. Both types are part of the <acronym>SQL</acronym>
|
||||
standard.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
When rounding values, the <type>numeric</type> type rounds ties away
|
||||
from zero, while (on most machines) the <type>real</type>
|
||||
and <type>double precision</type> types round ties to the nearest even
|
||||
number. For example:
|
||||
|
||||
<programlisting>
|
||||
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)
|
||||
</programlisting>
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user