Java Utility Library

Java Currency - toString() Method



The java.util.Currency.toString() method returns the ISO 4217 currency code of this currency.

Syntax

public String toString()

Parameters

No parameter is required.

Return Value

Returns the ISO 4217 currency code of this currency.

Exception

NA.

Example:

In the example below, the java.util.Currency.toString() method is used to get the ISO 4217 currency code of the given currency.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a currency for UK locale
    Locale locale = Locale.UK;
    Currency Curr = Currency.getInstance(locale);

    //getting and printing the ISO 4217 currency code
    String CurrCode = Curr.toString();
    System.out.println("ISO 4217 currency code is: " + CurrCode);
  }
}

The output of the above code will be:

ISO 4217 currency code is: GBP

❮ Java.util - Currency