开发者

How to format money in PostgreSQL

I have float field that contains (for example): 1234.5678. I would like to display it like a 1 234.56 or 1 234,5开发者_运维百科6. How can I do that?

I used to_char() function that gives me:

SELECT to_char(12345.5678,'99999999999999999D99');
-> 12345,57

but, when I have zero-value...

SELECT to_char(0,'99999999999999999D99');
-> ,00


A zero inside:

SELECT to_char(0,'99999999999999990D99');
-- Second question from the comments: Howto make k-seperator
SELECT to_char (1234567890999999.8,'99 999 999 999 999 990D99');

Here is the online-doku: functions (data-type conversion). Maybe you like to download it.


Would also use trim to remove extra whitespace

SELECT trim(to_char(12345.67,'99999999999999999D99'));

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜