Re: numeric and float converts to int differently?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: SZŰCS Gábor <surrano(at)mailbox(dot)hu>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: numeric and float converts to int differently?
Date: 2003-10-28 16:26:22
Message-ID: 23857.1067358382@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"=?iso-8859-2?B?U1rbQ1MgR+Fib3I=?=" <surrano(at)mailbox(dot)hu> writes:
> QUESTION 1: Is it intentional that converting 0.5 to int4
> - from numeric: rounds *away from* zero
> - from float: rounds *towards* zero (tried float4 and float8 too)?

Numeric currently rounds away from zero. We cannot guarantee to make
it work the same as float, because float's rounding behavior is
platform-dependent. A common but not universal behavior is "round to
nearest even integer". See the recent thread about the round() function
(I forget which list it was in, but it was within the past week).

> QUESTION 2: Is it safe to assume it won't change (haven't changed) in the
> upcoming versions?

Numeric's behavior hasn't changed as of 7.4beta5. I do not have a
crystal ball to predict whether we might change it in the future.
I doubt we will ever try to override the platform behavior for float.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message SZŰCS Gábor 2003-10-28 16:42:10 Re: numeric and float converts to int differently?
Previous Message Christoph Haller 2003-10-28 15:43:12 Re: URGENT!!! changing Column size