1

蟒蛇2.6:

import locale
locale.setlocale(locale.LC_MONETARY, 'fr_CA.UTF-8')
locale.currency(1.234) # '1,23 $'

Postgres 9.1:

set lc_monetary = 'fr_CA.UTF-8';
select 1.234::money; -- '$1,23'

我认为 Python 版本是正确的(虽然不是 100% 肯定),但它们怎么可能不同呢?

4

2 回答 2

1

加拿大有两种货币格式(在这方面它们很可能是独一无二的)。有加拿大英语 (en_CA) 和加拿大法语 (fr_CA)。

以我有限的理解,Python 的格式对于加拿大法语似乎是正确的,而 PostgreSQL 似乎使用的是加拿大英语。

PostgreSQL 中的货币支持完全有可能每个国家只允许一种格式。多年来,它并没有得到太多的关注和关注,大多数人使用数字进行财务计算,然后让客户端代码处理格式。

如果它对您很重要,可能值得发布错误报告(甚至是补丁)。

于 2013-04-08T17:11:49.690 回答
0

正如 Tom Lane 在 PG-general 邮件列表中报告的那样,这个问题在 9.2 中得到了修复:

Support more locale-specific formatting options for the money
data type (Tom Lane)

Specifically, honor all the POSIX options for ordering of the
value, sign, and currency symbol in monetary output. Also, make
sure that the thousands separator is only inserted to the left
of the decimal point, as required by POSIX.

我在 OSX 上使用 9.2.4 进行了尝试,确实有效。

于 2013-04-09T00:09:03.607 回答