Problems with currency formatting using toString()

3 views
Skip to first unread message

Thad Guidry

unread,
Oct 23, 2020, 3:24:42 PM10/23/20
to openref...@googlegroups.com
Tom and devs,

Here is the test GREL example (with long whitespace from a real receipt processing system I'm helping someone with privately):

"                       41,70 Eur".partition(" Eur")[0].trim().toString(FR,"%.2f")

Where I'm trying to reformat to 41.70

Does toString() not support the Locale? or we didn't wire it up?  (the Formatter printf parameters are driving me insane)

Because I get the following error showing in preview:

Error: toString accepts an object and an optional second argument containing a date format string

Here's the related issue that I quickly scanned again to see your comments and help jog my memory:

On a related note, I'm beginning to think that perhaps we might want to offer a new GREL function called "formatCurrency()" (not convertCurrency which would do outbound lookups of exchange rates and definitely need opt-in by users) and that can utilize JSR-354 Java Money (https://jcp.org/en/jsr/detail?id=354) but until that materializes we could potentially utilize the Moneta Java Money reference implementation of it?

Tom Morris

unread,
Oct 23, 2020, 4:06:46 PM10/23/20
to openref...@googlegroups.com
On Fri, Oct 23, 2020 at 3:24 PM Thad Guidry <thadg...@gmail.com> wrote:

Does toString() not support the Locale?

No, it doesn't. That's what the comment, "We should also think about how we extend this to non-default locales", in the issue you referenced is talking about. If you want French formatting, you'll need to set the default locale for the JVM e.g. java -Duser.country=FR -Duser.language=fr for the JVM that's running the OpenRefine server.

Here's the related issue that I quickly scanned again to see your comments and help jog my memory:

Tom 

Thad Guidry

unread,
Oct 23, 2020, 5:04:59 PM10/23/20
to openref...@googlegroups.com
Thanks Tom.
That's what I was afraid of...constantly having to restart OpenRefine to override the setting when switching back and forth between projects, instead of manipulating the Locale at runtime directly with toString() and toNumber().

Hmm, can it be manipulated via runtime?



--
You received this message because you are subscribed to the Google Groups "OpenRefine Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openrefine-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openrefine-dev/CAE9vqEGD7y9TrSWEHkC%3DsUmroDKGY6JWBisAU5GMjwj4n%2BVh5w%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages