本文整理匯總了Java中org.javamoney.moneta.format.AmountFormatParams類的典型用法代碼示例。如果您正苦於以下問題:Java AmountFormatParams類的具體用法?Java AmountFormatParams怎麽用?Java AmountFormatParams使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AmountFormatParams類屬於org.javamoney.moneta.format包,在下文中一共展示了AmountFormatParams類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: print
import org.javamoney.moneta.format.AmountFormatParams; //導入依賴的package包/類
@Override
public void print(Appendable appendable, MonetaryAmount amount)
throws IOException {
if (amountFormatContext.get(AmountFormatParams.GROUPING_SIZES, int[].class) == null ||
amountFormatContext.get(AmountFormatParams.GROUPING_SIZES, int[].class).length == 0) {
appendable.append(this.formatFormat.format(amount.getNumber()
.numberValue(BigDecimal.class)));
return;
}
this.formatFormat.setGroupingUsed(false);
String preformattedValue = this.formatFormat.format(amount.getNumber()
.numberValue(BigDecimal.class));
String[] numberParts = splitNumberParts(this.formatFormat,
preformattedValue);
if (numberParts.length != 2) {
appendable.append(preformattedValue);
} else {
if (numberGroup==null) {
char[] groupChars = amountFormatContext.get(AmountFormatParams.GROUPING_GROUPING_SEPARATORS, char[].class);
if (groupChars == null || groupChars.length == 0) {
groupChars = new char[]{this.formatFormat
.getDecimalFormatSymbols().getGroupingSeparator()};
}
int[] groupSizes = amountFormatContext.get(AmountFormatParams.GROUPING_SIZES, int[].class);
if (groupSizes == null) {
groupSizes = new int[0];
}
numberGroup = new StringGrouper(groupChars, groupSizes);
}
preformattedValue = numberGroup.group(numberParts[0])
+ this.formatFormat.getDecimalFormatSymbols()
.getDecimalSeparator() + numberParts[1];
appendable.append(preformattedValue);
}
}
示例2: print
import org.javamoney.moneta.format.AmountFormatParams; //導入依賴的package包/類
@Override
public void print(Appendable appendable, MonetaryAmount amount)
throws IOException {
if (amountFormatContext.get(AmountFormatParams.GROUPING_SIZES, int[].class) == null ||
amountFormatContext.get(AmountFormatParams.GROUPING_SIZES, int[].class).length == 0) {
appendable.append(this.formatFormat.format(amount.getNumber()
.numberValue(BigDecimal.class)));
return;
}
this.formatFormat.setGroupingUsed(false);
String preformattedValue = this.formatFormat.format(amount.getNumber()
.numberValue(BigDecimal.class));
String[] numberParts = splitNumberParts(this.formatFormat,
preformattedValue);
if (numberParts.length != 2) {
appendable.append(preformattedValue);
} else {
if (Objects.isNull(numberGroup)) {
char[] groupChars = amountFormatContext.get(AmountFormatParams.GROUPING_GROUPING_SEPARATORS, char[].class);
if (groupChars == null || groupChars.length == 0) {
groupChars = new char[]{this.formatFormat
.getDecimalFormatSymbols().getGroupingSeparator()};
}
int[] groupSizes = amountFormatContext.get(AmountFormatParams.GROUPING_SIZES, int[].class);
if (groupSizes == null) {
groupSizes = new int[0];
}
numberGroup = new StringGrouper(groupChars, groupSizes);
}
preformattedValue = numberGroup.group(numberParts[0])
+ this.formatFormat.getDecimalFormatSymbols()
.getDecimalSeparator() + numberParts[1];
appendable.append(preformattedValue);
}
}
示例3: main
import org.javamoney.moneta.format.AmountFormatParams; //導入依賴的package包/類
public static void main(String... args) {
MonetaryAmount amt = Money.of(1234.5678, "EUR");
System.out.println(amt.query(MonetaryFormats.getAmountFormat(Locale.GERMANY)));
System.out.println(MonetaryFormats.getAmountFormat(Locale.GERMANY).format(amt));
amt = Money.of(123412341234.5678, "INR");
System.out.println(MonetaryFormats.getAmountFormat(new Locale("", "INR")).format(amt));
// no with adaptive groupings
System.out.println(MonetaryFormats.getAmountFormat(
AmountFormatQueryBuilder.of(new Locale("", "INR"))
.set(AmountFormatParams.GROUPING_SIZES, new int[]{2, 3})
.set(AmountFormatParams.GROUPING_GROUPING_SEPARATORS, new char[]{',', '`'})
.build())
.format(amt));
}