Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display 2 digits after dot in PostgreSQL?

Tags:

sql

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?

like image 976
quack Avatar asked Feb 23 '16 09:02

quack


3 Answers

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

like image 115
Ram Singh Avatar answered Sep 18 '22 02:09

Ram Singh


Did you try:

Select round(price,2) from prices

like image 22
Ross Avatar answered Sep 19 '22 02:09

Ross


try this

select price::decimal(16,2) from prices
like image 45
Ryabchenko Alexander Avatar answered Sep 22 '22 02:09

Ryabchenko Alexander