Java中的 DecimalFormatSymbols setCurrency() 方法及示例
Java中Java .text.DecimalFormatSymbols类的setCurrency(Currency)方法用于设置这个DecimalFormatSymbols的Locale的货币。该方法以货币为参数并设置它。
句法:
public void setCurrency(Currency currency)
参数:此方法接受货币作为参数,该参数是将用于表示此 DecimalFormatSymbols 的货币的货币。
返回值:此方法不设置任何内容。
异常:如果货币为空,此方法将抛出NullPointerException 。
程序:
// Java program to demonstrate
// the above method
import java.text.*;
import java.util.*;
public class DecimalFormatSymbolsDemo {
public static void main(String[] args)
{
DecimalFormatSymbols dfs
= new DecimalFormatSymbols();
System.out.println("Current currency: "
+ dfs.getCurrency());
Currency currency
= Currency.getInstance("INR");
dfs.setCurrency(currency);
System.out.println("Updated currency: "
+ dfs.getCurrency());
}
}
输出:
Current currency: USD
Updated currency: INR
参考: https://docs.oracle.com/javase/9/docs/api/ Java/text/DecimalFormatSymbols.html#setCurrency-java.util.Currency-