How to round off to 3 decimal places in psql?

Viewed 90
select trim(TO_CHAR((15000.991234)::float, '999G999G99G999G99G99G990D99'))  as qty

Expected Output:
15,000.991

I want 3 decimal precison (3 numbers after point (dot)) and at the same time i want comma separation too and want result in char

2 Answers

What about:

select trim(TO_CHAR((round(15000.991234, 3))::float, '999G999G99G999G99G99G990D999'))  as qty

Just use the round function before converting it to char.

Edit: Forgot to mention you were missing a '9' and the end of the format-string.

Add an extra 9 to your string:

SELECT trim(to_char((15000.991234)::float, '999G999G99G999G99G99G990D999'))  as qty 

    qty     
------------
 15.000,991

Demo: db<>fiddle

Related