Skip to content

Commit 1c5a093

Browse files
committed
Fixed JAVAMONEY-92, enabling correct consideration of custom formats.
1 parent f9cbce6 commit 1c5a093

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/main/java/org/javamoney/moneta/format/internal/AmountNumberToken.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ public String getNumberPattern() {
8686
public void print(Appendable appendable, MonetaryAmount amount)
8787
throws IOException {
8888
int digits = amount.getCurrency().getDefaultFractionDigits();
89-
this.formatFormat.setMinimumFractionDigits(digits);
90-
this.formatFormat.setMaximumFractionDigits(digits);
9189
if (amountFormatContext.get("groupingSizes", int[].class) == null ||
9290
amountFormatContext.get("groupingSizes", int[].class).length == 0) {
9391
appendable.append(this.formatFormat.format(amount.getNumber()

src/test/java/org/javamoney/moneta/format/MonetaryAmountFormatTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.money.format.MonetaryAmountFormat;
2828
import javax.money.format.MonetaryFormats;
2929

30+
import org.javamoney.moneta.Money;
3031
import org.testng.annotations.Test;
3132

3233
/**
@@ -148,4 +149,26 @@ public void testParse() throws ParseException {
148149
.create(), defaultFormat.parse("12,50 CHF"));
149150
}
150151

152+
153+
/**
154+
* Test related to {@link https://java.net/jira/browse/JAVAMONEY-92}.
155+
*/
156+
@Test
157+
public void testWithCustomPattern() {
158+
MonetaryAmountFormat format = MonetaryFormats.getAmountFormat(
159+
AmountFormatQueryBuilder.of(Locale.GERMANY)
160+
.set(CurrencyStyle.SYMBOL)
161+
.set("pattern", "#,##0.00### ¤")
162+
.build());
163+
Money money = Money.of(12345.23456789, "EUR");
164+
assertEquals("12.345,23457 €", format.format(money));
165+
166+
format = MonetaryFormats.getAmountFormat(
167+
AmountFormatQueryBuilder.of(Locale.GERMANY)
168+
.set(CurrencyStyle.SYMBOL)
169+
.build());
170+
assertEquals("12.345,23 €", format.format(money));
171+
172+
173+
}
151174
}

0 commit comments

Comments
 (0)