Java 中 number format getcurrency instance()方法,带示例
原文:https://www . geesforgeks . org/number format-getcurrency instance-method-in-Java-with-examples/
-
The getCurrencyInstance() method is a built-in method of the java.text.NumberFormat returns a currency format for the current default FORMAT locale.
语法:
java public static final NumberFormat getCurrencyInstance()
参数:该功能不接受任何参数。
返回值:该函数返回货币格式的 NumberFormat 实例
下面是上述功能的实现:
程序 1:
```java // Java program to implement // the above function
import java.text.NumberFormat; import java.util.Locale; import java.util.Currency;
public class Main { public static void main(String[] args) throws Exception {
// Get the currency instance NumberFormat nF = NumberFormat .getCurrencyInstance();
// Sets the currency to Canadian Dollar nF.setCurrency( Currency.getInstance( Locale.CANADA));
// Stores the values String values = nF.getCurrency() .getDisplayName();
// Prints the currency System.out.println(values); } } ```
Output:
```java Canadian Dollar
```
程序 2:
```java // Java program to implement // the above function
import java.text.NumberFormat; import java.util.Locale; import java.util.Currency;
public class Main { public static void main(String[] args) throws Exception {
// Get the currency instance NumberFormat nF = NumberFormat .getCurrencyInstance();
// Stores the values String values = nF.getCurrency() .getDisplayName();
// Prints the currency System.out.println(values); } } ```
Output:
```java US Dollar
```
-
The getCurrencyInstance(Locale inLocale) method is a built-in method of the java.text.NumberFormat returns a currency format for any specifies locale.
语法:
java public static NumberFormat getCurrencyInstance?(Locale inLocale)
参数:该函数接受一个描述要指定的语言环境的强制参数。
返回值:该函数返回货币格式的 NumberFormat 实例。
下面是上述功能的实现:
程序 1:
```java // Java program to implement // the above function import java.text.NumberFormat; import java.util.Locale; import java.util.Currency; public class Main { public static void main(String[] args) throws Exception {
// Get the instance NumberFormat nF = NumberFormat .getCurrencyInstance( Locale.CANADA);
// Stores the values String values = nF.getCurrency() .getDisplayName();
// Prints the currency System.out.println(values); } } ```
Output:
```java Canadian Dollar
```
版权属于:月萌API www.moonapi.com,转载请注明出处