Search Postgresql Archives

R: Rounding problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>>"Paolo Saudin" <paolo@xxxxxxxxxxx> writes:
>> I have a problem with a query wich simple aggregate values. In the sample
>> below I have two values, 1.3 and 1.4. Rounding their average with one
>> decimals, should give 1.4.
>
>You seem way overoptimistic about float4 values being exact.  They are
>not.  The actual computation being done here is more like
>
>regression=# select (1.3::real + 1.4::real) / 2 ;           
>     ?column?     
>------------------
> 1.34999990463257
> (1 row)
>
>If you want an exact sum with no roundoff error you should be storing
>all your values as numeric (and taking the consequent speed and space
>hit :-().
>
>			regards, tom lane
>


I converted all the fields in numeric type instead of real and now both
queries return the same result !
Now I need to test about performances ...

Thank you very much !!
Paolo Saudin


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux