Обсуждение: using float4, I get incorrect value when select

Поиск
Список
Период
Сортировка

using float4, I get incorrect value when select

От
"Anibal David Acosta F."
Дата:
Hello, I have a table, with a float4 column, when I insert a new row and for
example I use this value "5000542,5" in the column of type float4, the
insert do OK, but when I select (select myColumn from myTable) I get the
value "5000540" I don't know why.

But if I cast to float8 (select cast(myColumn as float8) from myTable) I get
the correct value ("5000542,5").

I don't know if I am doing something wrong.. Please help me. Thanks

P.D.: I am using postgres 8.1 for windows

Anibal



Re: using float4, I get incorrect value when select

От
Martijn van Oosterhout
Дата:
On Sun, Oct 01, 2006 at 10:47:27PM -0400, Anibal David Acosta F. wrote:
> Hello, I have a table, with a float4 column, when I insert a new row and for
> example I use this value "5000542,5" in the column of type float4, the
> insert do OK, but when I select (select myColumn from myTable) I get the
> value "5000540" I don't know why.
>
> But if I cast to float8 (select cast(myColumn as float8) from myTable) I get
> the correct value ("5000542,5").

Do you understand the concept of floating point and the difference
between float4 and float8? Floating point throws away digits that it
doesn't have room to store, and with float4 that occurs after about 6
digits.

If you want to remember exact numbers, use numeric.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Вложения

Re: using float4, I get incorrect value when select

От
"Anibal David Acosta F."
Дата:
I am newbie in postgres.
But I think that the value is stored correctly because when select and cast
the column to float8 the postgres return the correct value and when I
insert, no overflow or other error occur.

Thanks Martijn


"Martijn van Oosterhout" <kleptog@svana.org> escribi� en el mensaje
news:20061002160116.GC29699@svana.org...