本文介绍了Linux服务器上缺少货币符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要显示货币符号的Java应用程序。我正在Linux(Ubuntu)服务器上运行。



在Linux服务器上LANG = en_GB.UTF-8



以下代码测试了该问题:

  import java.util.Currency; 
import java.util.Locale;
import java.text.NumberFormat;

公共类SymbolTest
{
public static void main(String [] args)
{
System.out.println( H​​ardcoded Unicode Currency Symbol为GBP [\u00A3]);
System.out.println(带有区域设置[[+ Currency.getInstance(Locale.UK).getSymbol()+]的GBP的货币符号);
System.out.println(带有区域设置[[+ Currency.getInstance(Locale.US).getSymbol()+]的美国货币符号);
System.out.println(带有语言环境[[+ Currency.getInstance(Locale.FRANCE).getSymbol()+]的法国的货币符号);
}
}

给出输出:



GBP的硬编码Unicode货币

带有区域设置[£]的GBP的货币符号



具有区域设置[USD]的美国货币符号

具有区域设置[â]的法国的货币符号

我怀疑这是Ubuntu服务器上的Locale或Lang问题。
我应该在linux服务器上安装/配置什么以显示货币符号?

解决方案

您的程序是正确尝试输出UTF-8,但是您的终端显然不知道它应该处于UTF-8模式。所以您的终端在这里有问题。您使用的是什么终端?



尝试将程序的输出重定向到文件,并使用支持UTF-8的编辑器打开该文件,以验证输出是否正确。


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?

解决方案

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.

这篇关于Linux服务器上缺少货币符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 00:43