Re: BUG #3959: Huge calculation error

Поиск
Список
Период
Сортировка
От Magnus Hagander
Тема Re: BUG #3959: Huge calculation error
Дата
Msg-id 47B2D35D.1000806@hagander.net
обсуждение исходный текст
Ответ на BUG #3959: Huge calculation error  ("Renaud Diez" <rdiez@salesprize.com>)
Список pgsql-bugs
Renaud Diez wrote:
> The following bug has been logged online:
>
> Bug reference:      3959
> Logged by:          Renaud Diez
> Email address:      rdiez@salesprize.com
> PostgreSQL version: 8.2
> Operating system:   Debian
> Description:        Huge calculation error
> Details:
>
> the basic mathematical expression like the following one doesn't compute the
> correct result:
>
>> select 100*(1+(21/100));
>
> return a result of 100 instead of 121.

It does compute the correct result, because you're doing integer
calculations. 21/100 for integers is 0. To make it do float calc, you can do
select 100*(1+(21::float/100));

Or you can do
select 100*(1+(21.0/100));

which will force it to numeric.

//Magnus

В списке pgsql-bugs по дате отправления:

Предыдущее
От: "Renaud Diez"
Дата:
Сообщение: BUG #3959: Huge calculation error
Следующее
От: "Heikki Linnakangas"
Дата:
Сообщение: Re: BUG #3959: Huge calculation error