Skip to content
New issue

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

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

Already on GitHub? # to your account

Change Money.toString() to show currency code at end #297

Closed
stokito opened this issue Feb 18, 2019 · 4 comments
Closed

Change Money.toString() to show currency code at end #297

stokito opened this issue Feb 18, 2019 · 4 comments
Milestone

Comments

@stokito
Copy link
Member

stokito commented Feb 18, 2019

Not sure if this should be discussed here or on API level but I wan't to propose to change behavior of MonetaryAmount.toString() methods. Currently they return a string when first is a currency code and then follows an amount i.e. USD 42.01. But numbers are Arabic numbers i.e. written from right to left and should be right justified when rendered in tables so the currency code should be on the end.

left align right align right align and code at end
BTC 0.0001 BTC 0.0001 0.0001 BTC
USD 0.00 USD 0.00 0.00 USD
USD 42.00 USD 42.00 42.00 USD
USD 9000 USD 9000 9000 USD
USD 100500.00 USD 100500 100500 USD

I added an example with Bitcoin to show that actually it should be aligned to point but for most cases it will be enough just to make a simple align to right.

So maybe in v2 we can change this behavior?

@atsticks
Copy link
Member

This is arguable and an implementation detail. We basically can do that change. I would also add a ticket to use default rounding based on the currency for formatting the amount as well.

@keilw keilw added this to the .Next milestone Jul 4, 2019
@keilw
Copy link
Member

keilw commented Jul 4, 2019

I's nothing for the API, even the style for formatting and everything else is currently part of the RI, not API. As this is a breaking change that affects all sorts of parse and serialization aspects (e.g. the JSON libraries) it must be done with great caution and enough notice for users to adopt. IMO it should be possible to configure e.g. in a javamoney.properties or other configuration (maybe the RI could even use something like Tamaya then ;-) so it can be overriden. Whether or not the default is left or right, we can see, but it clearly isn't for the MR.

@atsticks
Copy link
Member

The current solution (starting with this release) dies:

  1. Apply defaukt rounding according to the currency of the amount.
  2. Apply default formatting based on the current default locale.

@stokito
Copy link
Member Author

stokito commented Sep 13, 2019

Please take a look on my comment #307 (comment) about the current solution.

Here I talked exactly about the universal serialization form i.e. not about the localized format to display for users.
I guess here the proper format should depend on a some standard de-facto in financial applications if it ever existed.
I googled and here what I found:

What is the difference between 20$ and $20

Here is a discussion more about a tradition of the currency sign position in different countries.
We can't chose any country's format as a standard but at least for USA this makes sense: we already using number format from USA and most of financial institutions are from USA or at least working with them.

American dollar (symbol) (Linguistic recommendation from the Translation Bureau)

Here is clearly said that in financial world the currency code is always in the end (as I proposed).

Anyway, this should be specified in the specification so please reopen the task at least to keep a discussion and finalize the decision.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants