Re: How can I accurately infer the output of a SELECT statement FROM a table with floating-point data type? - Mailing list pgsql-general

From Tomek
Subject Re: How can I accurately infer the output of a SELECT statement FROM a table with floating-point data type?
Date
Msg-id CACUaW3RVpQdEqNqQnSVdoJhv63gqEUvxLJkkMsBpy1Mg2-KUig@mail.gmail.com
Whole thread Raw
In response to How can I accurately infer the output of a SELECT statement FROM a table with floating-point data type?  (毛毛 <krave@163.com>)
List pgsql-general
Hi,

May be you think about this ?

SELECT REAL_COLUMN, to_char(REAL_COLUMN,'9.99999EEEE') 6_significant_numbers_format FROM TEST;

Regards Tomek

czw., 19 paź 2023 o 05:47 毛毛 <krave@163.com> napisał(a):
Hi,

Do we have a rule by follow which one can accurately info the output of a SELECT statment FROM a table with floating-point data type?

I am working with PostgreSQL 16 and pgAdmin 7.6.

Here is my SQL script:

```
CREATE TABLE TEST (REAL_COLUMN real);

INSERT INTO TEST
VALUES (12345.123456789);

SELECT * FROM TEST;
```

I consulted the following doc and found that the range of real type is 6 decimal digits precision.

So I thought the output of the SELECT statement should be like: 12345.1 with 6 digits in total.
But it turns out to be 12345.123 with 8 digits in total.
May I know why would this happen?
Do we have a rule I can use to infer the correct output of a floating-point number without running the script?

Thank you for your time and have a great day!

pgsql-general by date:

Previous
From: Sebastien Flaesch
Date:
Subject: Build fails on RHEL 8.8 about libxml2 version
Next
From: "Wen Yi"
Date:
Subject: My question about the transaction