Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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

pgsql-sql by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group