skip to Main Content

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!

2

Answers


  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?

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search