Class USDCurrency

java.lang.Object
net.okapia.osid.primordium.financials.spi.AbstractCurrency
net.okapia.osid.primordium.financials.USDCurrency
All Implemented Interfaces:
Serializable, Comparable<Currency>, Currency, OsidPrimitive, Currency, OsidPrimitive

public final class USDCurrency extends AbstractCurrency implements Currency
USD Currency with arbitrary precision. The amounts can be any decimal number greater than or equal to zero. A USDCurrency may have a Precision where input amounts are rounded to DOLLAR, CENT, or MILL. ARBITRARY Precision will leave the input amounts alone. A USDCurrency supports two output formats. One using the $ SYMBOL and the other using a USD suffix.
See Also:
  • Constructor Details

  • Method Details

    • toString

      @OSIDBinding public String toString()
      Returns a string representation of this Currency.
      Specified by:
      toString in interface OsidPrimitive
      Overrides:
      toString in class AbstractCurrency
      Returns:
      a string
    • currency

      public static Currency currency(String str)
      Makes a USDCurrency from a string. The Precision is based on the decimal places in the supplied string and the output format is determined by the symbols in the supplied string. Formats are:
      • $D ($1,500)
      • D USD (1,500 USD)
      • $D.CC ($1,500.00)
      • D.CC USD (1,500.00 USD)
      • $D.CCCCC ($1,500.00000)
      • D.CCCCC USD (1,500.00000 USD)
      Parameters:
      str - a string representation of the amount
      Returns:
      a Currency
      Throws:
      InvalidArgumentException - cannot parse str
      NullArgumentException - str is null
      See Also:
    • valueOf

      public static Currency valueOf(String str)
      Makes a USDCurrency from a string. The Precision is based on the decimal places in the supplied string and the output format is determined by the symbols in the supplied string. Formats are:
      • $D ($1,500)
      • D USD (1,500 USD)
      • $D.CC ($1,500.00)
      • D.CC USD (1,500.00 USD)
      • $D.CCCCC ($1,500.00000)
      • D.CCCCC USD (1,500.00000 USD)
      Parameters:
      str - a string representation of the amount
      Returns:
      a Currency
      Throws:
      InvalidArgumentException - cannot parse str
      NullArgumentException - str is null
      See Also:
    • valueOf

      public static Currency valueOf(BigDecimal amount)
      Makes a USDCurrency from a BigDecimal. The Precision is based on the scale of the BigDecimal and the output format is Format.SYMBOL.
      Parameters:
      amount - the currency amount
      Returns:
      a Currency
      Throws:
      InvalidArgumentException - amount is negative
      NullArgumentException - amount is null
      See Also:
    • currency

      public static Currency currency(BigDecimal amount)
      Makes a USDCurrency from a BigDecimal. The Precision is based on the scale of the BigDecimal and the output format is Format.SYMBOL.
      Parameters:
      amount - the currency amount
      Returns:
      a Currency
      Throws:
      InvalidArgumentException - amount is negative
      NullArgumentException - amount is null
      See Also:
    • valueOf

      public static Currency valueOf(BigDecimal amount, USDCurrency.Format format)
      Makes a USDCurrency from a BigDecimal. The Precision is based on the scale of the BigDecimal.
      Parameters:
      amount - the currency amount
      format - the output format
      Returns:
      a Currency
      Throws:
      InvalidArgumentException - amount is negative
      NullArgumentException - amount or format is null
    • valueOf

      public static Currency valueOf(long cents)
      Makes a USDCurrency from a number of cents. The Precision is set to Precision.CENT and the output format is Format.SYMBOL.
      Parameters:
      cents - the number of cents
      Returns:
      a Currency
      Throws:
      InvalidArgumentException - cents is negative
      See Also:
    • currency

      public static Currency currency(long cents)
      Makes a USDCurrency from a number of cents. The Precision is set to Precision.CENT and the output format is Format.SYMBOL.
      Parameters:
      cents - the number of cents
      Returns:
      a Currency
      Throws:
      InvalidArgumentException - cents is negative
      See Also:
    • valueOf

      public static Currency valueOf(long cents, USDCurrency.Format format)
      Makes a USDCurrency from a number of cents. The Precision is set to Precision.CENT.
      Parameters:
      cents - the currency cents
      format - the output format
      Returns:
      a Currency
      Throws:
      InvalidArgumentException - cents is negative