pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Laurenz Albe <laurenz.albe@cybertec.at>
Cc: kamiya33hirokazu@gmail.com
Cc: pgsql-docs@lists.postgresql.org
Subject: Re: Explanation of the ROUND function with NUMERIC as an argument
Date: Sat, 03 Dec 2022 09:19:40 -0500
Message-ID: <2241115.1670077180@sss.pgh.pa.us> (raw)
In-Reply-To: <3da3dcc06220f80537dc1fb2c32cb76c91f87b93.camel@cybertec.at>
References: <167005767233.1899.2490889277144246641@wrigleys.postgresql.org>
	<3da3dcc06220f80537dc1fb2c32cb76c91f87b93.camel@cybertec.at>

Laurenz Albe <laurenz.albe@cybertec.at> writes:
> On Sat, 2022-12-03 at 08:54 +0000, PG Doc comments form wrote:
>> I am thinking that the value of the ROUND function with NUMERIC as an
>> argument is rounded off, not rounded away from zero.

> It is rounded away from zero, since 43 is farther away from 0 than 42.5.
> This may be a language problem.

Perhaps, since I don't see anything wrong with that text either.
(Of course, it's moderately likely that I wrote that text,
or at least copy-edited it at some point ;-).  Don't remember.)

The point is that for 42.5, or anything-point-5, the basic
"round to nearest integer" rule is insufficient because 42 and
43 are equally near.  We need a tie-breaking rule, and for numeric
that rule has historically been to round to the larger absolute
value (or "away from zero", as the text puts it to avoid two-dollar
terminology).  Sadly, that is not what IEEE has established as
best practice for floating-point rounding, so round(float8)
acts differently.

			regards, tom lane





view thread (4+ messages)  latest in thread

Message-ID: <2241115.1670077180@sss.pgh.pa.us>
Permalink:  ../2241115.1670077180@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2241115.1670077180@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, laurenz.albe@cybertec.at, kamiya33hirokazu@gmail.com, pgsql-docs@lists.postgresql.org
  Subject: Re: Explanation of the ROUND function with NUMERIC as an argument
  In-Reply-To: <2241115.1670077180@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox