本文整理汇总了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));
}