how to restore data values that already converted into scientific notation in a table

417 Views Asked by At

so i have a problem where i inserted some values into my table that the value automatically converted into a scientific notation (ex: 8.24e+04) does anyone know how restore the original value or how keep the original values in the table?

i'm using double precision as data type for the column and i just noticed that double precision data type often convert long number values into scientific notation.

this is how table looks like after i inserted some values

test=# select * from demo;
| string_col |        values         |
|------------|-----------------------|
| Rocket     |          123228435521 |
| Test       |        13328422942213 |
| Power      | 1.243343991231232e+15 |
| Pull       | 1.233433459353712e+15 |
| Drag       |         1244375399128 |

edb=# \d+ demo;
                                             Table "public.demo"
   Column   |         Type          | Collation | Nullable | Default | Storage  | Stats target | Description
------------+-----------------------+-----------+----------+---------+----------+--------------+-------------
 string_col | character varying(20) |           |          |         | extended |              |
 values     | double precision      |           |          |         | plain    |              |
Access method: heap

this just some dummy table i used to explain my question here.

1

There are 1 best solutions below

0
Laurenz Albe On

You'll have to format the number using to_char if you want it in a specific format:

SELECT 31672516735473059594023526::double precision,
       to_char(
          31672516735473059594023526::double precision,
          '999999999999999999999999999.99999999999999FM'
       );

        float8         │          to_char           
═══════════════════════╪════════════════════════════
 3.167251673547306e+25 │ 31672516735473058997862400
(1 row)

The result is not exact because the precision of double precision is not high enough.

If you don't want the rounding errors and want to avoid scientific notation as well, use the data type numeric instead.