Re: Should casting to integer produce same result as trunc() - Mailing list pgsql-general

From Tom Lane
Subject Re: Should casting to integer produce same result as trunc()
Date
Msg-id 25886.1318340505@sss.pgh.pa.us
Whole thread Raw
In response to Re: Should casting to integer produce same result as trunc()  (Alban Hertroys <haramrae@gmail.com>)
Responses Re: Should casting to integer produce same result as trunc()  (Alban Hertroys <haramrae@gmail.com>)
List pgsql-general
Alban Hertroys <haramrae@gmail.com> writes:
> On 11 Oct 2011, at 2:55, Harvey, Allan AC wrote:
>> My simple understanding of trunc() and casting to an integer says that
>> there is a bug here.

> Which the type-cast should round to 4380103 and 4380104 respectively.
> It doesn't:

That's because a cast from float to int rounds, it doesn't truncate.

regression=# select (4.7::float8)::int;
 int4
------
    5
(1 row)


            regards, tom lane

pgsql-general by date:

Previous
From: Eric Radman
Date:
Subject: Global Variables?
Next
From: Alban Hertroys
Date:
Subject: Re: Global Variables?