Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p1TMu-0001C6-Hy for pgsql-docs@arkaria.postgresql.org; Sat, 03 Dec 2022 14:19:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p1TMs-0000Em-NS for pgsql-docs@arkaria.postgresql.org; Sat, 03 Dec 2022 14:19:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p1TMs-0000Ed-Eh for pgsql-docs@lists.postgresql.org; Sat, 03 Dec 2022 14:19:50 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p1TMl-0003Or-Pd for pgsql-docs@lists.postgresql.org; Sat, 03 Dec 2022 14:19:49 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 2B3EJePE2241116; Sat, 3 Dec 2022 09:19:40 -0500 From: Tom Lane To: Laurenz Albe cc: kamiya33hirokazu@gmail.com, pgsql-docs@lists.postgresql.org Subject: Re: Explanation of the ROUND function with NUMERIC as an argument In-reply-to: <3da3dcc06220f80537dc1fb2c32cb76c91f87b93.camel@cybertec.at> References: <167005767233.1899.2490889277144246641@wrigleys.postgresql.org> <3da3dcc06220f80537dc1fb2c32cb76c91f87b93.camel@cybertec.at> Comments: In-reply-to Laurenz Albe message dated "Sat, 03 Dec 2022 14:34:56 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2241114.1670077180.1@sss.pgh.pa.us> Date: Sat, 03 Dec 2022 09:19:40 -0500 Message-ID: <2241115.1670077180@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz Albe 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