joda-money icon indicating copy to clipboard operation
joda-money copied to clipboard

Support for formatter formats

Open yarrouye opened this issue 10 years ago • 5 comments

Hi,

I was looking at the source for Joda Money as it has no way to get a formatter for a specific locale, and noticed a couple commented out functions in MoneyFormatterBuilder taking patterns... Is that something you are working on and is coming up, or something that was abandoned?

yarrouye avatar Mar 17 '14 21:03 yarrouye

Its something I was too busy to finish. I think patterns like that would be a good feature.

jodastephen avatar Mar 17 '14 22:03 jodastephen

I agree. Is this something you're going to get back to?

I would probably want to use the standard notation for patterns (i.e. ###.## and using the currency symbol etc. rather than or at least in addition to a verbose format with {$someName}" which may be what you had in mind with your singletons? And I also think that part of localization should also support for proper use of separators between amounts and currencies.

I would actually have put those in a MoneyFormat class, similar to DateTimeFormat in Joda Time. What do you think? I may give it a shout... if so I'd appreciate understanding your thinking behind what you had started.

On Mon, Mar 17, 2014 at 3:10 PM, Stephen Colebourne < [email protected]> wrote:

Its something I was too bus to finish. I think patterns like that would be a good feature.

— Reply to this email directly or view it on GitHubhttps://github.com/JodaOrg/joda-money/issues/38#issuecomment-37877343 .

yarrouye avatar Mar 17 '14 22:03 yarrouye

I think a combination of ### type patterns and $ type patterns would be useful. Feel free to propose something, I'm not going to get to work on it anytime soon.

In general, Joda-Time tends to try to be reasonably compatible with JDK patterns, so I'd expect money to do the same. No need to slavishly follow JDK mistakes though.

jodastephen avatar Mar 17 '14 22:03 jodastephen

I agree re: compatibility. The main issue I see right now with the Joda Money formatter (at a VERY quick glance) is that it treats the currency and the amount as two very separate things, when really they are not. For example, the default way to format "-123.33 in USD" in Java and other frameworks for the Locale.US locale is "($123.33)" where the parenthesis come from the fact that the amount is negative, and the rest is regular currency formatting. Your pattern APIs seem to have that going on, but I do not know if those would be easy to map to your singletons (I guess one could always write a singleton that always write abs(amount) and use that appropriately when mapping patterns).

The Printer/Parser concept works well outside of the builder in any case; I was able to whip out a MoneyFormat.forLocale(Locale) that returned a formatter implementing both the printer and parser interfaces using the JDK's DecimalFormat class in very few lines of codes. However, I put this in my own libraries rather than yours as I believe the latter would require a grounds up implementation of the code; and I haven't found a good public source of currency formats I could bring into such code...

On Mon, Mar 17, 2014 at 3:24 PM, Stephen Colebourne < [email protected]> wrote:

I think a combination of ### type patterns and $ type patterns would be useful. Feel free to propose something, I'm not going to get to work on it anytime soon.

In general, Joda-Time tends to try to be reasonably compatible with JDK patterns, so I'd expect money to do the same. No need to slavishly follow JDK mistakes though.

— Reply to this email directly or view it on GitHubhttps://github.com/JodaOrg/joda-money/issues/38#issuecomment-37878674 .

yarrouye avatar Mar 18 '14 04:03 yarrouye

Just to note that the elements within the formatter do not have to be singletons, they can be private immutable inner classes with state. See Joda-Time/JSR-310 formatter for examples of this.

Currency/Money data is present in CLDR, which is where Oracle/JDK gets its data.

jodastephen avatar Mar 18 '14 09:03 jodastephen