Java Currency getNumericCode() 方法



描述

Java Currency getNumericCode() 方法獲取此貨幣的 ISO 4217 數字程式碼。

宣告

以下是 java.util.Currency.getNumericCode() 方法的宣告

public int getNumericCode()

引數

返回值

此方法返回此貨幣的 ISO 4217 數字程式碼。

異常

獲取 EUR 貨幣的數字程式碼示例

以下示例演示了 Java Currency getNumericCode() 方法在 EUR 貨幣上的用法。我們首先使用 EUR 作為貨幣程式碼建立了一個貨幣物件,然後列印其數字程式碼。

package com.tutorialspoint;

import java.util.Currency;

public class CurrencyDemo {
   public static void main(String args[]) {

      // create a currency with EUR code
      Currency curr = Currency.getInstance("EUR");

      System.out.println("Numeric Code for EUR = " + curr.getNumericCode());
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Numeric Code for EUR = 978

獲取 USD 貨幣的數字程式碼示例

以下示例演示了 Java Currency getNumericCode() 方法在 USD 貨幣上的用法。我們首先使用 USD 作為貨幣程式碼建立了一個貨幣物件,然後列印其數字程式碼。

package com.tutorialspoint;

import java.util.Currency;

public class CurrencyDemo {
   public static void main(String args[]) {

      // create a currency with USD code
      Currency curr = Currency.getInstance("USD");

      System.out.println("Numeric Code for USD = " + curr.getNumericCode());
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Numeric Code for USD = 840

獲取 INR 貨幣的數字程式碼示例

以下示例演示了 Java Currency getNumericCode() 方法在 INR 貨幣上的用法。我們首先使用 INR 作為貨幣程式碼建立了一個貨幣物件,然後列印其數字程式碼。

package com.tutorialspoint;

import java.util.Currency;

public class CurrencyDemo {
   public static void main(String args[]) {

      // create a currency with INR code
      Currency curr = Currency.getInstance("INR");

      System.out.println("Numeric Code for INR = " + curr.getNumericCode());
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Numeric Code for INR = 356
java_util_currency.htm
廣告

© . All rights reserved.