Reputation: 51
I am new to postgres and presently migrating from sql server to postgres and facing some problems. Kindly help me with this.
I am not being able to convert to decimal whenever the answer is in whole number. Whenever the answer is in whole number,
decimal conversion results in only giving the integer part as the answer.
For example :- If the result is 48 decimal conversion gives 48 whereas I want 48.00.
Upvotes: 0
Views: 703
Reputation: 65
You can round the value by using the statement
select round(48,2);
It will return 48.00. You can also round to more decimal points.
Upvotes: 0
Reputation: 51649
you can start from using numeric(4,2)
, instead of decimal, eg:
t=# select 48::numeric(4,2);
numeric
---------
48.00
(1 row)
or even:
t=# select 48*1.00;
?column?
----------
48.00
(1 row)
but keep in mind the fact you don't see zeroes in decimal does not mean the number is not decimal. eg here it is still float:
t=# select 48::float;
float8
--------
48
(1 row)
Upvotes: 2