0

I have an Insert in a table (ex. field a1) which is a calculated value in a SELECT field01Value/1000000 .

How can I format the field to display 20 or more decimals after the operation. I tried CAST(field01Value as double precision)/1000000 but the value is displayed as 2E-5. Thanks!

Lay N
  • 9
  • 2

3 Answers3

0

I suggest a cast to numeric(precision, scale) instead. Scale would be 20 in your case, and precision the maximum number of digits you would allow.

select field01Value/1000000::numeric(30,20)
from mytable

Demo here : https://dbfiddle.uk/DLfdUN_Y

SelVazi
  • 10,028
  • 2
  • 13
  • 29
0

In PostgreSQL, you may use the ROUND() function and the ::numeric cast to show the calculated result with a given number of decimal places without using scientific notation. Here's an illustration:

SELECT (field01Value::numeric / 1000000)::numeric(30, 20) AS calculated_value
FROM your_table;
-1

Have you tried ROUND function ?

SELECT ROUND(field01Value::numeric / 1000000, 20) AS calculated_value
FROM table;

Seems duplicate :- How to round an average to 2 decimal places in PostgreSQL?

Manish Kumar
  • 595
  • 2
  • 15