Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Suggested fix for #10.

  • Loading branch information...
commit 976b88762538befbba80196e5fbcfdf071693dad 1 parent 1ec3d9a
tkeinone authored
View
5 src/main/java/org/joda/money/format/AmountPrinterParser.java
@@ -20,6 +20,7 @@
import java.math.BigDecimal;
import org.joda.money.BigMoney;
+import org.joda.money.MoneyUtils;
/**
* Prints and parses the amount part of the money.
@@ -45,6 +46,10 @@
//-----------------------------------------------------------------------
public void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException {
MoneyAmountStyle activeStyle = style.localize(context.getLocale());
+ if (MoneyUtils.isNegative(money)) {
+ money = money.negated();
+ appendable.append(activeStyle.getNegativeSignCharacter());
+ }
String str = money.getAmount().toPlainString();
char zeroChar = activeStyle.getZeroCharacter();
if (zeroChar != '0') {
View
8 src/test/java/org/joda/money/format/TestMoneyFormatterBuilder.java
@@ -37,6 +37,7 @@
private static final Money GBP_2_34 = Money.parse("GBP 2.34");
private static final Money GBP_23_45 = Money.parse("GBP 23.45");
private static final Money GBP_234_56 = Money.parse("GBP 234.56");
+ private static final Money GBP_MINUS_234_56 = Money.parse("GBP -234.56");
private static final Money GBP_2345_67 = Money.parse("GBP 2345.67");
private static final Money GBP_1234567_89 = Money.parse("GBP 1234567.89");
private static final BigMoney GBP_1234_56789 = BigMoney.parse("GBP 1234.56789");
@@ -396,6 +397,13 @@ public void test_appendAmountLocalized_GBP_234_56() {
assertEquals(test.toString(), "${amount}");
}
+ public void test_appendAmountLocalized_GBP_MINUS_234_56() {
+ iBuilder.appendAmountLocalized();
+ MoneyFormatter test = iBuilder.toFormatter(Locale.FRANCE);
+ assertEquals(test.print(GBP_MINUS_234_56), "-234" + FR_DECIMAL + "56");
+ assertEquals(test.toString(), "${amount}");
+ }
+
public void test_appendAmountLocalized_GBP_2345_67() {
iBuilder.appendAmountLocalized();
MoneyFormatter test = iBuilder.toFormatter(Locale.FRANCE);
Please sign in to comment.
Something went wrong with that request. Please try again.