2

I have a text file that contains $ and € currency signs. The dollar signs are shown well while the € currencies are shown as empty boxes in a javafx table. I was wondering which charset do I have to use in order to show the euro currency sign ?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ramses
  • 652
  • 2
  • 8
  • 30

2 Answers2

2

Why dont you just use Locale?

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

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
displayCurrency(new Locale("FR","FR"));
    }
    static public void displayCurrency( Locale currentLocale) {

        Double currencyAmount = new Double(9876543.21);
        Currency currentCurrency = Currency.getInstance(currentLocale);
        NumberFormat currencyFormatter = 
            NumberFormat.getCurrencyInstance(currentLocale);

        System.out.println(
            currentLocale.getDisplayName() + ", " +
            currentCurrency.getDisplayName() + ": " +
            currencyFormatter.format(currencyAmount));
    }
}

Output

French (France), Euro: 9 876 543,21 €

Aleksandar Đokić
  • 2,118
  • 17
  • 35
1

You need the charset of the text-file, the $ is in basic ascii so it will show nearly always, the €-Symbol is for example in ISO-8859-15 or in UTF-8. But as I said, it depends mainly on the textfile correctly read in, Java internally uses UTF-16 and has it covered. And on output with UTF-8 you're on the safe side.

Alim Özdemir
  • 2,396
  • 1
  • 24
  • 35
  • I used ISO_8859_1 to correctly read my text file to later load it into a table. Anyway, I unfortunately still get the not the sign when I use UTF-8 – Ramses Aug 02 '16 at 22:45