Package net.thauvin.erik.frankfurter
Class CurrencyFormatter
java.lang.Object
net.thauvin.erik.frankfurter.CurrencyFormatter
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
NumberFormatinstances, so no external synchronization is required.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringFormats a monetary amount using the locale conventions associated with the given ISO currency code.static StringFormats a monetary amount using the locale conventions associated with the given ISO currency code.static StringFormats a monetary amount using the locale's currency and conventions.static Stringformat(double amount, CurrencyCode code) Formats a monetary amount using the locale conventions associated with the given currency.static Stringformat(double amount, CurrencyCode code, boolean rounded) Formats a monetary amount using the locale conventions associated with the given currency.
-
Method Details
-
format
Formats a monetary amount using the locale conventions associated with the given currency.- Parameters:
amount- the numeric amountcode- the currency (must not benull)- Returns:
- the formatted currency string
- Throws:
NullPointerException- ifcodeisnull- See Also:
-
format
Formats a monetary amount using the locale conventions associated with the given currency.- Parameters:
amount- the numeric amountcode- the currency (must not benull)rounded- whether to round to the locale's default fraction digits- Returns:
- the formatted currency string
- Throws:
NullPointerException- ifcodeisnull- See Also:
-
format
Formats a monetary amount using the locale conventions associated with the given ISO currency code.- Parameters:
amount- the numeric amountisoCode- the ISO 4217 currency code (must not benullor blank)- Returns:
- the formatted currency string
- Throws:
IllegalArgumentException- ifisoCodeisnull, blank, or unknown- See Also:
-
format
Formats a monetary amount using the locale conventions associated with the given ISO currency code.- Parameters:
amount- the numeric amountisoCode- the ISO 4217 currency code (must not benullor blank)rounded- whether to round to the locale's default fraction digits- Returns:
- the formatted currency string
- Throws:
IllegalArgumentException- ifisoCodeisnull, blank, or unknown- See Also:
-
format
Formats a monetary amount using the locale's currency and conventions.- Currency – Determined by
localeonly. PassingLocale.USformats as USD. - Rounding – Always uses
RoundingMode.HALF_UProunded=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 formatlocale- locale for currency + format rules; must not benullrounded-truefor currency digits,falsefor 15 digits max- Returns:
- formatted currency string, never
null - Throws:
NullPointerException- iflocaleisnull
- Currency – Determined by
-