Re: [GENERAL] Rounding Double Precision or Numeric - Mailing list pgsql-general

From Steve Atkins
Subject Re: [GENERAL] Rounding Double Precision or Numeric
Date
Msg-id 43BF799B-EF60-48C2-9220-0C1881F2CA36@blighty.com
Whole thread Raw
In response to [GENERAL] Rounding Double Precision or Numeric  (Louis Battuello <louis.battuello@etasseo.com>)
Responses Re: [GENERAL] Rounding Double Precision or Numeric  (Scott Marlowe <scott.marlowe@gmail.com>)
List pgsql-general
> On Jun 1, 2017, at 9:26 AM, Louis Battuello <louis.battuello@etasseo.com> wrote:
>
> Is the round() function implemented differently for double precision than for numeric? Forgive me if this exists
somewherein the documentation, but I can't seem to find it. 

https://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-NUMERIC-DECIMAL

"When rounding values, the numeric type rounds ties away from zero, while (on most machines) the real and double
precisiontypes round ties to the nearest even number.". 

> Why does the algorithm vary by data type?

Just guessing, but I'd assume because the NUMERIC type behaves as required by the SQL spec, while float and double are
vanillaIEEE754 arithmetic and will do whatever the underlying hardware is configured to do, usually round to nearest
even.

Cheers,
  Steve



pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: [GENERAL] Slow query plan used
Next
From: Scott Marlowe
Date:
Subject: Re: [GENERAL] Rounding Double Precision or Numeric