Class CurrencyFormatter

java.lang.Object
net.thauvin.erik.frankfurter.CurrencyFormatter

public final class CurrencyFormatter extends Object
Provides locale‑aware formatting of monetary amounts using ISO 4217 currency codes. The formatter uses a static lookup table mapping each currency to a representative locale. The locale determines grouping, decimal separators, and symbol placement.
API Note:
This class is thread‑safe. All state is immutable and formatting operations create new NumberFormat instances, so no external synchronization is required.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    format(double amount, String isoCode)
    Formats a monetary amount using the locale conventions associated with the given ISO currency code.
    static String
    format(double amount, String isoCode, boolean rounded)
    Formats a monetary amount using the locale conventions associated with the given ISO currency code.
    static String
    format(double amount, Locale locale, boolean rounded)
    Formats a monetary amount using the locale's currency and conventions.
    static String
    format(double amount, CurrencyCode code)
    Formats a monetary amount using the locale conventions associated with the given currency.
    static String
    format(double amount, CurrencyCode code, boolean rounded)
    Formats a monetary amount using the locale conventions associated with the given currency.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • format

      @NonNull public static String format(double amount, @NonNull CurrencyCode code)
      Formats a monetary amount using the locale conventions associated with the given currency.
      Parameters:
      amount - the numeric amount
      code - the currency (must not be null)
      Returns:
      the formatted currency string
      Throws:
      NullPointerException - if code is null
      See Also:
    • format

      @NonNull public static String format(double amount, @NonNull CurrencyCode code, boolean rounded)
      Formats a monetary amount using the locale conventions associated with the given currency.
      Parameters:
      amount - the numeric amount
      code - the currency (must not be null)
      rounded - whether to round to the locale's default fraction digits
      Returns:
      the formatted currency string
      Throws:
      NullPointerException - if code is null
      See Also:
    • format

      @NonNull public static String format(double amount, @NonNull String isoCode)
      Formats a monetary amount using the locale conventions associated with the given ISO currency code.
      Parameters:
      amount - the numeric amount
      isoCode - the ISO 4217 currency code (must not be null or blank)
      Returns:
      the formatted currency string
      Throws:
      IllegalArgumentException - if isoCode is null, blank, or unknown
      See Also:
    • format

      @NonNull public static String format(double amount, @NonNull String isoCode, boolean rounded)
      Formats a monetary amount using the locale conventions associated with the given ISO currency code.
      Parameters:
      amount - the numeric amount
      isoCode - the ISO 4217 currency code (must not be null or blank)
      rounded - whether to round to the locale's default fraction digits
      Returns:
      the formatted currency string
      Throws:
      IllegalArgumentException - if isoCode is null, blank, or unknown
      See Also:
    • format

      @NonNull public static String format(double amount, @NonNull Locale locale, boolean rounded)
      Formats a monetary amount using the locale's currency and conventions.
      • Currency – Determined by locale only. Passing Locale.US formats as USD.
      • Rounding – Always uses RoundingMode.HALF_UP
        • rounded=true – Uses currency's default fraction digits. USD=2, JPY=0.
        • rounded=false – Uses up to 15 fraction digits to preserve precision.
      Parameters:
      amount - the numeric amount to format
      locale - locale for currency + format rules; must not be null
      rounded - true for currency digits, false for 15 digits max
      Returns:
      formatted currency string, never null
      Throws:
      NullPointerException - if locale is null