jsr354-ri
jsr354-ri copied to clipboard
Allow more customisation of toString formats - specifically dropping the currency code
I have a use case where i present many amounts all of the same currency on one table. I want to remove the currency code from the toString which is used by my templating framework. The ui will just indicate that the entire table is in one currency.
I've patched the RI to allow just "a" as the format string, which does what I need.
Would you be able to share this patch or PR here?
Yes sure - but you won't like it ;), here it is. Allows you to specify just 'a' as the format:
Index: moneta-core/src/main/java/org/javamoney/moneta/ToStringMonetaryAmountFormat.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/moneta-core/src/main/java/org/javamoney/moneta/ToStringMonetaryAmountFormat.java b/moneta-core/src/main/java/org/javamoney/moneta/ToStringMonetaryAmountFormat.java
--- a/moneta-core/src/main/java/org/javamoney/moneta/ToStringMonetaryAmountFormat.java (revision cfcc7e42ab89659cd5f8222e1fb3ff78aedaf806)
+++ b/moneta-core/src/main/java/org/javamoney/moneta/ToStringMonetaryAmountFormat.java (revision b8e36f54f4f9effa19186cf54c01a65a5474b21c)
@@ -104,6 +104,8 @@
case "a c":
case "a-c":
return dec.toPlainString() + " " + m.getCurrency().getCurrencyCode();
+ case "a":
+ return dec.toPlainString();
case "currency-amount":
case "currency amount":
case "ca":
Although it's probably faster to wrap Money in your own class, and use Lombok's @Delegate
annotation and then override the toString formatter. That's what I ended up doing as there were other things I needed to change too.