1
0
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:
Tom Lane
2015-07-03 17:04:39 -04:00
parent 8eb6407aae
commit 5e7c3d91bf
10 changed files with 169 additions and 0 deletions

View File

@ -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>