public abstract class BaseMonetaryAmountFormat extends Object implements MonetaryAmountFormat
MonetaryAmount to a String or an Appendable.
To obtain a MonetaryAmountFormat for a specific locale, including the default
locale, call MonetaryFormats.getAmountFormat(java.util.Locale, String...).
More complex formatting scenarios can be implemented by registering instances of .MonetaryAmountFormatProviderSpi.
The spi implementation creates new instances of BaseMonetaryAmountFormat based on the
styleId and (arbitrary) attributes passed within the AmountFormatContext.
In general, do prefer
accessing MonetaryAmountFormat instances from the MonetaryFormats singleton,
instead of instantiating implementations directly, since the MonetaryFormats factory
method may return different subclasses or may implement contextual behaviour (in a EE context).
If you need to customize the format object, do something like this:
MonetaryAmountFormat f = MonetaryFormats.getInstance(loc);
f.setStyle(f.getStyle().toBuilder().setPattern("###.##;(###.##)").build());
Special Values
Negative zero ("-0") should always parse to
0// Print out a number using the localized number, currency,
// for each locale</strong>
Locale[] locales = MonetaryFormats.getAvailableLocales();
MonetaryAmount amount = ...;
MonetaryAmountFormat form;
System.out.println("FORMAT");
for (int i = 0; i < locales.length; ++i) {
if (locales[i].getCountry().length() == 0) {
continue; // Skip language-only locales
}
System.out.print(locales[i].getDisplayName());
form = MonetaryFormats.getInstance(locales[i]);
System.out.print(": " + form.getStyle().getPattern());
String myAmount = form.format(amount);
System.out.print(" -> " + myAmount);
try {
System.out.println(" -> " + form.parse(form.format(myAmount)));
} catch (ParseException e) {}
}
}| Constructor and Description |
|---|
BaseMonetaryAmountFormat() |
| Modifier and Type | Method and Description |
|---|---|
String |
format(MonetaryAmount amount)
Formats the given
MonetaryAmount to a String. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetContext, parse, printqueryFrompublic BaseMonetaryAmountFormat()
public String format(MonetaryAmount amount)
MonetaryAmount to a String.format in interface MonetaryAmountFormatamount - the amount to format, not nullUnsupportedOperationException - if the formatter is unable to printCopyright © 2012–2020 JavaMoney. All rights reserved.