建议我使用哪种 Java 格式来表示货币符号,以便它们可以轻松地显示在 JSP 页面上?

发布于 2024-12-02 04:58:49 字数 434 浏览 0 评论 0原文

JPYEUR 等。

我有一个针对每种可用货币的 3-alpha 货币代码表,例如:USD 当大多数人只显示货币符号($¥、 ETC)。

我还没有找到一个免费的 Java 库来将 3-alpha 货币代码转换为其相应的货币符号? Java Locale 功能有限且麻烦。

因此,我决定手动向现有表添加一个新列,并自己添加适当的货币符号。

但是,我不确定在表中以什么格式表示它们,以便可以轻松地将它们输出到JSP页面上?我应该复制粘贴维基百科上的符号吗?或者,如果我在某处获得了符号的 Unicode 值,那么让 JSP 将 Unicode 值转换为符号是否容易?我以前没有使用过 Unicode。

I have a table of 3-alpha currency codes for every available currency, e.g: USD, JPY, EUR, etc.

But it's a bit long-winded to display the 3-alpha codes on a web page when most people simply display a currency symbol ($, ¥, , etc).

I haven't been able to find a free Java library to convert the 3-alpha currency codes to their corresponding currency symbols? The Java Locale feature is limited and cumbersome.

So I've decided to manually add a new column to my existing table and add the appropriate currency symbols myself.

However, I am not sure in what format to represent them in the table so that they can be easily outputted on a JSP page? Should I copy-paste the symbols from Wikipedia? Or, if I get Unicode values for the symbols somewhere, is it easy to have a JSP convert the Unicode values to the symbols? I haven't worked with Unicode before.

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

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

发布评论

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

评论(4

还在原地等你 2024-12-09 04:58:49

您是否在 按照 javadocs 的货币

为什么这么麻烦呢?

Did you try getSymbol on Currency as per javadocs?

Why is it cumbersome?

画中仙 2024-12-09 04:58:49

如果您选择创建从货币缩写到符号的查找表,则最佳选择是使用 HTML 实体。有两种变体,您可能想同时使用两者。

首先,对于通用货币,有显式的实体,例如。您可以在此处找到它们的表格(某些符号将位于“Latin 1”中)页面,其他将在“其他特殊字符”页面)。

其次,对于非通用货币,应该使用 Unicode 转义。一般形式为 &#xnumber;,其中 number 是十六进制 Unicode 代码点值。有一个货币符号块,尽管您想要的符号可能是包含在另一个代码块中。查找代码块的起点是此处

不要简单地粘贴来自维基百科的符号,除非您了解编码的工作原理,以及 (1) 您的文件实际使用的编码,以及 (2) 您的网络服务器声称它们使用的编码。

If you choose to create a lookup table from a currency abbreviation to a symbol, the best choice is to use an HTML entity. There are two variants, and you'll probably want to use both.

First, for common currencies, there are explicit entities, such as . You'll find a table of them here (some symbols will be in the "Latin 1" page, others will be in the "Other Special Characters" page).

Second, for non-common currencies, you should use a Unicode escape. The general form is &#xnumber;, where number is the hexadecimal Unicode codepoint value. There is a block of currency symbols, although it's possible that the symbols you want are included in another code block. The starting point for finding a code block is here.

Do not simply paste symbols from Wikipedia, unless you understand how encodings work, along with (1) what encoding your files actually use, and (2) what encoding your web-server claims they use.

爱冒险 2024-12-09 04:58:49

也许您可以在语言文件中包含货币符号。

更新:删除了数据库的文本部分

Maybe you can have the currency symbols in your language file.

Updated: Removed the text part with the db

十雾 2024-12-09 04:58:49

NumberFormat 类是您想要的位置看。这将是特定于区域设置的,并且能够为您提供正确的编号。这是一个例子。

NumberFormat us = NumberFormat.getCurrencyInstance(Locale.US);
String usFormat = us.format(56.45);
System.out.println(usFormat);

NumberFormat uk = NumberFormat.getCurrencyInstance(Locale.UK);
String ukFormat = uk.format(56.45);
System.out.println(ukFormat);

你的输出将如下所示

$56.45
£56.45

The NumberFormat class is where you will want to look. This will be locale specific and be able to provide you with the proper numbering. Here is an example.

NumberFormat us = NumberFormat.getCurrencyInstance(Locale.US);
String usFormat = us.format(56.45);
System.out.println(usFormat);

NumberFormat uk = NumberFormat.getCurrencyInstance(Locale.UK);
String ukFormat = uk.format(56.45);
System.out.println(ukFormat);

your output will look like the following

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