Re: Unexpected result using floor() function

From: Vick Khera <vivek(at)khera(dot)org>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Unexpected result using floor() function
Date: 2016-03-14 14:28:03
Message-ID: CALd+dccuPH4hMibEngNh2UKfm1pw8bbe8iKNT+-dAg0oc7Yn9Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

100 is an integer
power(10,2) is a double precision.

Try this one:

SELECT floor(4.725 * 100::double precision + 0.5);

On Mon, Mar 14, 2016 at 10:11 AM, Frank Millman <frank(at)chagford(dot)com> wrote:

> Hi all
>
> I am running PostgreSQL 9.4.4 on Fedora 22.
>
> SELECT floor(4.725 * 100 + 0.5) returns 473, which is what I expected.
>
> SELECT floor(4.725 * power(10, 2) + 0.5) returns 472, which I find
> surprising.
>
> Please can someone explain the anomaly.
>
> Thanks
>
> Frank Millman
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2016-03-14 14:29:07 Re: Unexpected result using floor() function
Previous Message Pujol Mathieu 2016-03-14 14:21:12 Re: Unexpected result using floor() function