Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
Getting Specific symbols to appear using getCurrencyInstance() in Java

I'm writing a very simple and small example class to try and show how the .getCurrencyInstance() of the NumberFormat class in Java works, but my output is looking a little funky. It seems the class is working, but when it tries to print out the actual symbols for currency (like the Japanese yen symbol or the British pound symbol) I get weird symbols instead. Is there any way to fix this? Is there something I need to import to get these symbols on my computer?

Here's my code:

import java.util.*;
import java.text.*;

public class CurrencyFormatExample
{
   public static void main(String[] args)
   { 
      double convert = 9398.9398;

      NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
      System.out.println("American: " + currencyFormat.format(convert));

      Locale swedish = new Locale("sv", "SE");
      NumberFormat swedishFormat = NumberFormat.getCurrencyInstance(swedish);

      System.out.println("Swedish: " + swedishFormat.format(convert));

      Locale japanese = new Locale("ja", "JP");
      NumberFormat japaneseFormat = NumberFormat.getCurrencyInstance(japanese);

      System.out.println("Japanese: " + japaneseFormat.format(convert));

      Locale russian = new Locale("ru", "RU");
      NumberFormat russianFormat = NumberFormat.getCurrencyInstance(russian);

      System.out.println("Russian: " + russianFormat.format(convert));

      Locale british = new Locale("en", "GB");
      NumberFormat britishFormat = NumberFormat.getCurrencyInstance(british);

      System.out.println("British: " + britishFormat.format(convert));
   }
}

Here is the output I get with this:

American: $9,398.94
Swedish: 9á398,94 kr
Japanese: ?9,399
Russian: 9á398,94 ???.
British: ú9,398.94

As you can see that's clearly not right. Any way I can remedy this?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

If you're executing this code in Eclipse, adjust your Window > Preferences > General > Workspace text encoding to UTF-8

over 4 years ago · Santiago Trujillo Report

0

In jGRASP: "Settings" > "Font", "Charset" tab. Change "I/O Charset" to UTF-8. In the "Compiler" tab, "Flags / Args" sub-tab, for "FLAGS2" of the "Run" command, add "-Dfile.encoding=UTF-8".

The "file.encoding" change will also change the default encoding files that your program reads and writes. Unfortunately, Java does not provide a way to specify a different charset for normal file I/O and I/O from stdin, stdout, and stderr when they are connected to pipes rather than a console (most IDEs will use pipes). So if you want native encoding to be used by default within your program and still want UTF-8 for I/O to the IDE, there is no way to do it. Thus, it would not be wise for the IDE to automatically add the "file.encoding" flag, unless there is a "Just use UTF-8 for everything" setting.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!