如何在使用NumberFormat时在Eclipse控制台中显示”£”符号?

huangapple go评论87阅读模式
英文:

How to display "£" symbol in Eclipse console when using NumberFormat?

问题

我为我的班级制作了一个非常简单的程序。我唯一的问题是,当我使用locale和NumberFormat时,Eclipse会在控制台输出一个奇怪的符号,而不是"£"符号。

我的代码的一个小例子是:

Locale english = new Locale("en", "UK");
NumberFormat GBP = NumberFormat.getCurrencyInstance(english);

然后稍后我使用:

System.out.println("The total tax payable for the 6 months is: " + GBP.format(totalTax));

控制台输出给我:

£1,035.19

我尝试了设置中的每个编码选项,但似乎没有解决这个问题。

英文:

I've made a very simple program for my class. My only issue is when I use the locale and NumberFormat Eclipse is outputting a strange symbol to the console instead of the "£" symbol.

A small example of my code is:

Locale english = new Locale("en", "UK");
NumberFormat GBP = NumberFormat.getCurrencyInstance(english);

Then later I use:

System.out.println("The total tax payable for the 6 months is: " + GBP.format(totalTax));

The output to the console gives me:

 ¤1,035.19

I've tried each encoding option in the settings but none of them seem to fix the issue.

答案1

得分: 1

你应该使用 GB 代替 UK

Locale english = new Locale("en", "GB");
NumberFormat GBP = NumberFormat.getCurrencyInstance(english);
BigDecimal totalTax = BigDecimal.valueOf(12.34);
System.out.println("The total tax payable for the 6 months is: " + GBP.format(totalTax));

输出:

The total tax payable for the 6 months is: £12.34
英文:

You should use GB instead of UK.

Locale english = new Locale("en", "GB");
NumberFormat GBP = NumberFormat.getCurrencyInstance(english);
BigDecimal totalTax = BigDecimal.valueOf(12.34);
System.out.println("The total tax payable for the 6 months is: " + GBP.format(totalTax));

output

The total tax payable for the 6 months is: £12.34

huangapple
  • 本文由 发表于 2020年9月29日 05:34:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/64109917.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定