Re: [GENERAL] Rounding Double Precision or Numeric
От | Scott Marlowe |
---|---|
Тема | Re: [GENERAL] Rounding Double Precision or Numeric |
Дата | |
Msg-id | CAOR=d=378D2nH4=10s0wgPRxk8yHfqDGcWC4gBkaWwtiv=YoGQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: [GENERAL] Rounding Double Precision or Numeric (Steve Atkins <steve@blighty.com>) |
Ответы |
Re: [GENERAL] Rounding Double Precision or Numeric
|
Список | pgsql-general |
On Thu, Jun 1, 2017 at 10:42 AM, Steve Atkins <steve@blighty.com> wrote: > >> 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 arevanilla IEEE754 arithmetic and will do whatever the underlying hardware is configured to do, usually round to nearesteven. > Exactly. It's important to remember that floats and doubles are imprecise representations meant for speed, while numeric is designed for accuracy not speed. If one needs an exact answer, one does not use floats.
В списке pgsql-general по дате отправления: