Linux 服务器上缺少货币符号
我有一个java应用程序需要显示货币符号。我在 Linux(Ubuntu) 服务器上运行。
在 Linux 服务器上 LANG=en_GB.UTF-8
以下代码测试该问题:
import java.util.Currency;
import java.util.Locale;
import java.text.NumberFormat;
public class SymbolTest
{
public static void main(String[] args)
{
System.out.println("Hardcoded Unicode Currency Symbol for GBP [\u00A3] ");
System.out.println("Currency Symbol for GBP with Locale [" + Currency.getInstance(Locale.UK).getSymbol() + "]");
System.out.println("Currency Symbol for US with Locale [" + Currency.getInstance(Locale.US).getSymbol() + "]");
System.out.println("Currency Symbol for FRANCE with Locale [" + Currency.getInstance(Locale.FRANCE).getSymbol() + "]");
}
}
给出输出:
硬编码的 Unicode 货币符号 for GBP â £
货币符号 for GBP with Locale [â £]
货币符号 for US with Locale [USD]
货币符号对于带有区域设置的法国 [â]
我怀疑这是 Ubuntu 服务器上的区域设置或语言问题。 我应该在 Linux 服务器上安装/配置什么才能显示货币符号?
I have a java application that needs to display currency symbols. I'm running on a Linux(Ubuntu) server.
On Linux server LANG=en_GB.UTF-8
The following code tests the problem:
import java.util.Currency;
import java.util.Locale;
import java.text.NumberFormat;
public class SymbolTest
{
public static void main(String[] args)
{
System.out.println("Hardcoded Unicode Currency Symbol for GBP [\u00A3] ");
System.out.println("Currency Symbol for GBP with Locale [" + Currency.getInstance(Locale.UK).getSymbol() + "]");
System.out.println("Currency Symbol for US with Locale [" + Currency.getInstance(Locale.US).getSymbol() + "]");
System.out.println("Currency Symbol for FRANCE with Locale [" + Currency.getInstance(Locale.FRANCE).getSymbol() + "]");
}
}
gives the output:
Hardcoded Unicode Currency Symbol for GBP £
Currency Symbol for GBP with Locale [£]
Currency Symbol for US with Locale [USD]
Currency Symbol for FRANCE with Locale [â¬]
I suspect this is a Locale or Lang problem on the Ubuntu server.
What should I install/configure on the linux server to enable the currency symbols to display?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的程序正确地尝试输出 UTF-8,但您的终端显然不知道它应该处于 UTF-8 模式。所以你的终端有问题。您使用什么终端?
尝试将程序的输出重定向到一个文件,并使用支持 UTF-8 的编辑器打开该文件,以验证输出是否正确。
Your program is correctly trying to output UTF-8, but your terminal apparently doesn't know that it's supposed to be in UTF-8 mode. So your terminal is at fault here. What terminal are you using?
Try redirecting the output of the program to a file and open that file with a UTF-8 capable editor to verify that the output is correct.
我猜测这个问题可能与您实际格式化数字或区域设置而不是字体的方式有关。查看 有关将数字格式化为货币的 Grails 参考 和 java.util.Currency API 文档了解更多信息。排除字体相关问题的一种快速方法是将您要查找的符号键入(如有必要,复制并粘贴)到 GSP 中,并验证您是否可以在浏览器中查看它:
I'm guessing that the issue is probably related to the way you're actually formatting the number or locale rather than the font. Check out the Grails reference on formatting numbers as currency and the java.util.Currency API doc for more information. A quick way to rule out a font related issue is just to type (copy&paste if necessary) the symbol you're after into a GSP and verify that you can view it in your browser: