如何在 PostgreSQL 中格式化钱

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5419199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 22:55:28  来源:igfitidea点击:

How to format money in PostgreSQL

postgresql

提问by Bald

I have float field that contains (for example): 1234.5678. I would like to display it like a 1 234.56 or 1 234,56. How can I do that?

我有包含(例如)的浮动字段:1234.5678。我想将它显示为 1 234.56 或 1 234,56。我怎样才能做到这一点?

I used to_char()function that gives me:

我使用to_char()了给我的函数:

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

but, when I have zero-value...

但是,当我的值为零时......

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

回答by user unknown

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.

这是online-doku: functions (data-type conversion)。也许你喜欢下载它。

回答by user3078500

Would also use trim to remove extra whitespace

也将使用修剪去除多余的空格

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

选择修剪(to_char(12345.67,'99999999999999999D99'));