SOLVED

Re: Currency Formatting

Go to solution
Gary_Hagins
Level 2

Currency Formatting

So, I've setup our currency format as $10,000.00 (Admin > Location Settings) and I have a variable/token that is a currency. But when I use that currency, it's always formatted as "10000.00" when inserted as a token in an email--no $ or comma. Any ideas how to fix?

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: Currency Formatting

One way I have fixed this is using email scripting.  I will look into this for you however.  Email scripting can be found here:  developers.marketo.com

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

Re: Currency Formatting

One way I have fixed this is using email scripting.  I will look into this for you however.  Email scripting can be found here:  developers.marketo.com

Gary_Hagins
Level 2

Re: Currency Formatting

Perfect! That got me exactly what I needed (although I had to figure out which library to use, $number.currency() is easy enough!). For anyone else who's wondering, you just create an email script something like: {{my.Format Currency}} and then just do something like:

## First, covert the variable to currency format

#set($total = $number.currency(${lead.Total_Production__c_contact}))

## Next, check if variable is set. If it's not, set to "$0.00" to avoid showing an unset/blank variable

#if(!$total)

  #set($total = "$0.00")

#end

## Then, for the email output

Total: ${total}<br>

And then place that in your email template where you need it. Done!

Anonymous
Not applicable

Re: Currency Formatting

That script worked great! Just curious - would we need to reference a different library to get rid of the decimal points? (for example $200 instead of 200.00?)

Gary_Hagins
Level 2

Re: Currency Formatting

Marketo Resource: Email Scripting » Marketo Developers

Velocity Resource: VelocityTools - Summary

The trick in your question is knowing that number.curency() returns a pre-determined format. So, if you try and use something like a math.roundto(), or number.integer() it won't work.

But what you can do, is take the length of the string and subtract the last 3 digits! (the .00 portion) by knowing how many of the first few digits of string we want to keep.

#set($total = $number.currency(${lead.Production_REIT__c_contact})) ##our code from before, e.g., $121,237.10

#set($stringLength = $total.length() - 3) ##get the total string length and calculate what we want to keep, e.g., 8 --note the specific spacing between the commands here! screwing up the syntax will crash it (e.g. if you remove the space)

#set($totalb = $total.substring(0,$stringLength)) ##takes the sub string of just the first 3 characters, e.g., $121,237

I just tested on an email and that worked for me. Good luck!

Emily_Kucharczy
Level 2

Re: Currency Formatting

Do you have an example of your entire script? I tried the above and it didn't seem to work (I'm sure something I'm doing wrong). I was able to get the numbers to format like currency in an email. Now just trying to remove the .00 from the end of the integer.

Emily Kucharczyk
Anonymous
Not applicable

Re: Currency Formatting

Seeing the whole script in action would be great, not sure if I am supposed to be putting a value in the parenthesis ebfore the - 3,  #set($stringLength = $total.length() - 3) OR if my string is 8 characters long #set($stringLength = $total.length(8) - 3)

Anonymous
Not applicable

Re: Currency Formatting

This is the whole script I just got working based on Gary Hagins post (I'm realizing now I had ended the script with ${total} instead of the ${totalb}!

## First, covert the variable to currency format

#set($total = $number.currency(${lead.your_field_here})) ##our code from before, e.g., $121,237.10

#set($stringLength = $total.length() - 3) ##get the total string length and calculate what we want to keep, e.g., 8 --note the specific spacing between the commands here! screwing up the syntax will crash it (e.g. if you remove the space)

#set($totalb = $total.substring(0,$stringLength)) ##takes the sub string of just the first 3 characters, e.g., $121,237

## Then, for the email output

${totalb}

I noticed you said integer, we use a string field, that might be what is throwing your velocity script off

Emily_Kucharczy
Level 2

Re: Currency Formatting

We were using a currency field. This is ultimately what made our numbers format the way we wanted them to, i.e., 10,000.I then added in a $ in the HTML before the script token.

## First, covert the variable to currency format

#set($total = $number.integer(${lead.your_field}))

## Next, check if variable is set. If it's not, set to "$0" to avoid showing an unset/blank variable

#if(!$total)

  #set($total = "$0")

#end

## Then, for the email output

${total}

Emily Kucharczyk
Anonymous
Not applicable

Re: Currency Formatting

Ya know what, we have been using this script in two different situations, one with an integer and one with a currency field, not a string -- both seem to work fine. Thing is we don't include the fall back value - the only leads who can enter the campaigns we have set up is if the currency field has a value.

I'll post both here, one is an opportunity field and the other is from the lead level (be sure to double check that the fields your using are checked off!)

(opportunity level script)

## First, covert the variable to currency format

#set($total = $number.currency(${OpportunityList.get(0).o_your_opportunity_field_here})) ##our code from before, e.g., $121,237.10

#set($stringLength = $total.length() - 3) ##get the total string length and calculate what we want to keep, e.g., 8 --note the specific spacing between the commands here! screwing up the syntax will crash it (e.g. if you remove the space)

#set($totalb = $total.substring(0,$stringLength)) ##takes the sub string of just the first 3 characters, e.g., $121,237

## Then, for the email output

${totalb}

(lead level script)

## First, covert the variable to currency format

#set($total = $number.currency(${lead.your_lead_level_script})) ##our code from before, e.g., $121,237.10

#set($stringLength = $total.length() - 3) ##get the total string length and calculate what we want to keep, e.g., 8 --note the specific spacing between the commands here! screwing up the syntax will crash it (e.g. if you remove the space)

#set($totalb = $total.substring(0,$stringLength)) ##takes the sub string of just the first 3 characters, e.g., $121,237

## Then, for the email output

${totalb}