SOLVED

Velocity currency formatter

Go to solution
Phillip_Wild
Level 10

Velocity currency formatter

Hi all

 

I'm creating an email script which outputs a currency value based on the person's currency. So, for example, someone might have a value assigned of 1125.13 euros. My script should take the input, localise it by the currency that is selected, and give the output as a string for printing in the email. In the example above, 1125.13 euros would become €1.125,13 - since a comma is the fractional separator and a period is the thousands separator. 

 

I'm getting my formats from here: https://fastspring.com/blog/how-to-format-30-currencies-from-countries-all-over-the-world/. Now while I don't need all of the currencies here, I need a solid dozen of them, and the string formatting gets quite complicated. 

 

I've read about the .currency method under NumberTools - but I want to set the locale. Reading through something like this: https://groups.google.com/forum/#!topic/dotcms/Aax-lKAsWhk I feel that we can't change locale like this in Marketo's scripting....but maybe you can in a similar way to how you can do this with timezones?

 

Any ideas on how to do this? It really doesn't seem great to write complicated substring find and replaces, and then maintain that...

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity currency formatter

You can instantiate a Locale very simply:

#set( $formatted = $number.format("currency", $amount, $convert.toLocale("de_DE")) ) 

 

 

View solution in original post

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity currency formatter

You can instantiate a Locale very simply:

#set( $formatted = $number.format("currency", $amount, $convert.toLocale("de_DE")) ) 

 

 

Phillip_Wild
Level 10

Re: Velocity currency formatter

Wow. It really is that easy! Thanks so much Sanford.

Phillip_Wild
Level 10

Re: Velocity currency formatter

Hmm.....although I can't say I love some of the European formatting. For example, "en_CH" for Swiss francs gives "CHF633.62". 

 

Euros gives me something similarly crappy - "EUR663.62". 

 

I'm guessing I can't modify this easily without writing exceptions one by one.

 

I don't think I can hold that against you though Sanford! Hehe.