Currency class of java.util tools

JDK8 Online Api Chinese Manual

JDK8 Online Api English Manual

Currency class

   The Currency class encapsulates information about currencies and does not define a constructor. Table 1 lists the methods supported by the Currency class. The following program demonstrates the Currency class:

//Demonstrate Currency.
import java.util.Currency;
import java.util.Locale;
class CurDemo {
  public static void main(String[] args) {
      Currency c;
      c = Currency.getInstance(Locale.US);
      System.out.println("Symbol: "+c.getSymbol());
      System.out.println("Default fractional digits: "+c.getDefaultFractionDigits());
      /**
       * 输出:
       * Symbol: $
       * Default fractional digits: 2
       */
  }
}
Table 1 Methods defined by Currency class
method Description
static Set<Currency> getAvailableCurrencies() Returns a set of supported currencies
String getCurrencyCode() Returns the code describing the calling currency (defined by ISO 4127)
int getDefaultFractionDigits() Returns the number of digits after the decimal point used by the calling currency under normal circumstances. For example, for US dollars, normally use two decimal places
String getDisplayName() Returns the name of the calling currency in the default region
String getDisplayName(Locale loc) Returns the name of the calling currency in the specified region
static Currency getInstance(Locale localeObj) Returns the Currency object of the region specified by localeObj
static Currency getInstance(String code) Returns the Currency object associated with the currency code passed by the code
int getNumericCode() Returns the numeric code of the calling currency (defined by ISO 4217)
String getSymbol() Returns the currency symbol of the calling object (such as $)
String getSymbol(Locale localeObj) Returns the currency symbol of the region passed by localeObj (such as $)
String toString() Returns the currency code of the calling object
Published 59 original articles · won 20 · views 3633

Guess you like

Origin blog.csdn.net/qq_34896730/article/details/104229297