英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论