How to print special characters by CMD when formatting coins?

Asked

Viewed 72 times

0

A few days ago I did an exercise to format coins and used the following code for this:

String us, china, france;
us = NumberFormat.getCurrencyInstance(Locale.US).format(payment);
china = NumberFormat.getCurrencyInstance(Locale.CHINA).format(payment);
france = NumberFormat.getCurrencyInstance(Locale.FRANCE).format(payment);

In the command prompt should come out something like this:

US: $12,324.13
China: ¥12,324.13
France: 12 324,13 €

But something like that came out:

US: $12,324.13
China: ?12,324.13
France: 12▒324,13 ▒

I know the code is correct, because it worked, but it is not displayed in the right way. How do I so that whenever I need to run special characters by CMD they are displayed correctly?

  • 3

    I believe this problem is not of java, but of the encoding accepted by the prompt

  • I understand, but there is something that can be done to fix it, @Articuno?

1 answer

1


The most reliable would be using the GUI. Minimum example:

JOptionPane.showMessageDialog(null, new String[] {us, china, france});

In the CMD you will not be able to display all symbols correctly as it basically has no support for Unicode. With

> CHCP 1252

will be able to show the (Euro) but probably not the (\uFFE5, Yen). Maybe this page about CHCP help more...

Stackoverflow English has this question with some answers that may help.

  • I tried your suggestion to use Joptionpane and it worked too. I will use it when I need to run cmd/terminal! Thank you very much! ^_^

Browser other questions tagged

You are not signed in. Login or sign up in order to post.