如何在 javafx table 中显示欧元货币符号 €
How to show Euro Currency Sign € in a javafx table
我有一个包含 $ 和 € 货币符号的文本文件。美元符号显示良好,而欧元货币在 javafx table 中显示为空框。
我想知道我必须使用哪个字符集才能显示欧元货币符号 €?
您需要文本文件的字符集,$ 是基本的 ascii,所以它几乎总是会显示,€-Symbol 例如在 ISO-8859-15 或 UTF-8 中。
但正如我所说,这主要取决于正确读入的文本文件,Java 内部使用 UTF-16 并涵盖了它。在使用 UTF-8 输出时,你是安全的。
为什么不直接使用 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));
}
}
输出
French (France), Euro: 9 876 543,21 €
我有一个包含 $ 和 € 货币符号的文本文件。美元符号显示良好,而欧元货币在 javafx table 中显示为空框。 我想知道我必须使用哪个字符集才能显示欧元货币符号 €?
您需要文本文件的字符集,$ 是基本的 ascii,所以它几乎总是会显示,€-Symbol 例如在 ISO-8859-15 或 UTF-8 中。 但正如我所说,这主要取决于正确读入的文本文件,Java 内部使用 UTF-16 并涵盖了它。在使用 UTF-8 输出时,你是安全的。
为什么不直接使用 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));
}
}
输出
French (France), Euro: 9 876 543,21 €