Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow more customisation of toString formats - specifically dropping the currency code #364

Open
astubbs opened this issue Jul 16, 2021 · 2 comments
Labels
formatting Something about formatting and parsing
Milestone

Comments

@astubbs
Copy link

astubbs commented Jul 16, 2021

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.

@keilw
Copy link
Member

keilw commented Jul 27, 2021

Would you be able to share this patch or PR here?

@astubbs
Copy link
Author

astubbs commented Sep 2, 2021

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.

@keilw keilw added the deferred label Sep 16, 2021
@keilw keilw added this to the .Next milestone Sep 16, 2021
@keilw keilw modified the milestones: 1.5, .Next Aug 25, 2022
@keilw keilw added formatting Something about formatting and parsing and removed deferred labels Feb 20, 2024
@keilw keilw modified the milestones: .Next, 1.4.5 Feb 20, 2024
@keilw keilw changed the title Allow more customisation to toString formats - specifically dropping the currency code Allow more customisation of toString formats - specifically dropping the currency code Feb 20, 2024
@keilw keilw modified the milestones: 1.4.5, 1.5 Mar 15, 2024
@keilw keilw modified the milestones: 1.4.5, 1.5 Apr 25, 2024
@keilw keilw added this to Backlog Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatting Something about formatting and parsing
Projects
Status: No status
Development

No branches or pull requests

2 participants