Search Postgresql Archives

Re: SELECT with REAL...

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

 



Hi,

Thank you all for your comments.

Finally, I think I will simply use the data type NUMERIC instead of REAL in all my columns !!
This type is more appropriate to store prices !

Philippe Ferreira.


Try this:

SELECT 13.95 = 13.95::real;

It should yield false, because the first number constant is presumed to be of type numeric, which is an exact format, and the second constant is explicitly cast to a single precision floating point number, in which it doesn't fit*, and therefore actually is stored as 13.9499998**. So, the comparison is in fact 13.95=13.9499998, which of course is false.

To see the effect in another way, try:

SELECT 13.95::real + 0.00000000000001;

*) The reason it doesn't fit is that the floating point representation is using base 2, instead of base 10. **) The exact value could vary, depending on the floating point implementation of your system. This is what my implementation does.




[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