MySQL - 存储货币符号的最佳方式?

发布于 2024-11-28 04:29:07 字数 460 浏览 0 评论 0原文

只是想知道在 MySQL 数据库中存储货币值和符号的最佳方式是什么?

感谢浏览 SO,我将我的金额存储为小数 (19,2 )值 - 这很好 - 但我更关心货币符号(例如 €、£、$ 等),因为我希望允许最终用户在设置阶段设置自己的货币单位。我还想避免任何不确定性,目前设置为 utf8(双方)。

我目前的方法是将它们存储为 HTML 数字代码< /a> 使用 PHP ifelse 语句来过滤输入。这是最好的方法吗?如果不是,那是什么?有必要吗?提前致谢!

Just wondering what the best way of storing currency values and symbols within a MySQL DB might be?

Thanks to browsing SO, I'm storing my amounts as a Decimal (19,2) value - which is fine - but am more concerned with the Currency symbol (e.g. €, £, $, etc.), as I want to allow the end user to set their own currency unit at the set up stage. I also want to avoid any uncertainty as regards, which are currently set at utf8 (both sides).

The way I have at the moment is to store them as HTML Numerical Codes using PHP ifelse statements to filter input. Is this the best method? If not, what is? Is there a need at all? Many thankee's in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

遥远的绿洲 2024-12-05 04:29:07

我将使用 character (3) 并存储货币代码 ( http://en.wikipedia.org/wiki/ISO_4217#Active_codes)。例如欧元、美元、英镑等,并且仅在显示时显示适当的符号。

I would use a character (3) and store the currency code instead ( http://en.wikipedia.org/wiki/ISO_4217#Active_codes ). For example, EUR, USD, GBP etc., and only show the appropriate symbol at display-time.

美胚控场 2024-12-05 04:29:07

您可以将数据分成两列

amount      = decimal(19,2) --- question : unsigned for positive value only
currency_id = int(10) unsigned --- which is ID to currency table

恕我直言,当 currency 字段引用另一个表时, ,
您可以将所有类型的附加信息存储到该表中(例如汇率)
更好地描述您希望如何呈现符号

imho, you can break the data into two columns

amount      = decimal(19,2) --- question : unsigned for positive value only
currency_id = int(10) unsigned --- which is ID to currency table

when the currency field is reference to another table,
you can storing all sort of additional info into that table (such as exchange rate)
to better describe how you want the symbol get presented

孤独陪着我 2024-12-05 04:29:07

您是否考虑过根本不使用符号,而是使用 ISO 4217 三字母代码?

如有必要,请使用另一个表来处理从这些表到输出时更用户友好的符号格式的映射。

Have you considered not using symbols at all, but using ISO 4217 three letter codes instead?

If necessary, use another table to handle mapping from those into a more user-friendly symbol format on output.

罪歌 2024-12-05 04:29:07

您是否必须根据用户选择的货币来转换?如果是,您可以创建一个新表来存储货币符号和汇率。

如果您只想根据用户的区域设置显示货币,您可能需要尝试国际化库。

Do you have to convert the currency based on what the user choose? If yes, you can just make a new table for storing the currency symbol and the exchange rate.

If you just want to show the currency based on the user's locale, you may want to try an internationalization library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文