nimgwfc
nimgwfc

Reputation: 1509

Psql format number so that it always has two decimal places

If I have a number like this: 1205.5668 I know I can round to two decimal places by doing the following:

select round(1205.5668,2);

The above will return 1205.57 as expected.

How do I get two decimal places though if the number is already round? For example, I want 1200 to convert to 1200.00

I've tried select round(1200,2); but it just displays 1200

Upvotes: 2

Views: 4589

Answers (1)

Avinash Dalvi
Avinash Dalvi

Reputation: 9311

Try this :

SELECT round( CAST(float8 '1200.3363636' as numeric), 2);
SELECT round( CAST(float8 '1200' as numeric), 2);

enter image description here

Upvotes: 3

Related Questions