MySQL - 存储货币符号的最佳方式?
只是想知道在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我将使用
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.您可以将数据分成两列
恕我直言,当
currency
字段引用另一个表时, ,您可以将所有类型的附加信息存储到该表中(例如汇率)
更好地描述您希望如何呈现符号
imho, you can break the data into two columns
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
您是否考虑过根本不使用符号,而是使用 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.
您是否必须根据用户选择的货币来转换?如果是,您可以创建一个新表来存储货币符号和汇率。
如果您只想根据用户的区域设置显示货币,您可能需要尝试国际化库。
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.