Search code examples
sqlpostgresqlnumber-formattingnumeric

How to display 2 digits after dot in PostgreSQL?


I have a table which their values are NUMERIC(16,4)

Example:

12.4568
13.2
14.05

I want to display the value with only 2 digits after dot without rounding. Expected result is:

12.45
13.2
14.05

What I did is:

Select price::Numeric(16,2)
from prices

It works however I am not sure if this is the correct way to do it. I think it's better to use some kind of display edit rather then casting?


Solution

  • you can do this in following way:

    select round(cast(your_float_column as decimal(10,2)), 2, 1)
    from your_table
    

    If you just want to skip round off then

    select round(12333.347, 2, 1)
    

    hope this will work for you