SOLVED

Trying to get $ figure through velocity scripting... help?

Go to solution
Jervis_Koo
Level 1

Trying to get $ figure through velocity scripting... help?

Hey! 

We're currently using velocity script tokens for dynamic content on our emails and currently having some challenges with getting the script to show a dollar amount with the $ format. 

I was expecting the field lead.yearlyAmount to spit out the amount with the $ sign (field type is currency) but I guess that's not how it works so we've tried using the script below to no avail. The script doesn't seem to be parsing - any ideas?

#set($yearlyCurrency = $number.toNumber($lead.yearlyAmount))
$esc.dollar$number.format('#,###', $yearlyCurrency)

Any help would be appreciated!

Jervis

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Trying to get $ figure through velocity scripting... help?

First: you should never use Currency -- for anything -- despite the name. For round numbers, use Integer. For numbers with decimals, use scaled Integers (value * 100) and scale them back in Velocity or JS.

Also, please highlight code when posting using the syntax highlighter so it's readable. Highlight as Java as it's closest to VTL.

You don't need to convert to a Number (Double) separately, $number.format() does that conversion internally. Make sure you escape all your special Velocity symbols.

${number.format("${esc.d}${esc.h},${esc.h}${esc.h}${esc.h}", $lead.yearlyAmount)}

View solution in original post

16 REPLIES 16
SanfordWhiteman
Level 10 - Community Moderator

Re: Trying to get $ figure through velocity scripting... help?

First: you should never use Currency -- for anything -- despite the name. For round numbers, use Integer. For numbers with decimals, use scaled Integers (value * 100) and scale them back in Velocity or JS.

Also, please highlight code when posting using the syntax highlighter so it's readable. Highlight as Java as it's closest to VTL.

You don't need to convert to a Number (Double) separately, $number.format() does that conversion internally. Make sure you escape all your special Velocity symbols.

${number.format("${esc.d}${esc.h},${esc.h}${esc.h}${esc.h}", $lead.yearlyAmount)}
Jervis_Koo
Level 1

Re: Trying to get $ figure through velocity scripting... help?

Worked perfectly! Was doing my head in for a good few weeks.Thank you Sanford Whiteman‌! 

*also edited to highlight code 

SanfordWhiteman
Level 10 - Community Moderator

Re: Trying to get $ figure through velocity scripting... help?

Thanks a lot for the highlighting, helps others remember.

messier
Level 2

Re: Trying to get $ figure through velocity scripting... help?

How can I apply that same scripting to show a $ sign and a comma in an amount. For example, I tried to apply it this way, but no luck. (I am a very novice user)

 

${number.format("${esc.d}${esc.h},${esc.h}${esc.h}${esc.h}", $lead.APPBURSELAMNT)}
SanfordWhiteman
Level 10 - Community Moderator

Re: Trying to get $ figure through velocity scripting... help?

That is the correct syntax to output

12345

as

$12,345

 so we’d need to know what you mean by “no luck”.

messier
Level 2

Re: Trying to get $ figure through velocity scripting... help?

I entered the script into my token exactly as you edited it. The number still shows up without a comma and will has the ".0" at the end which is odd because the data coming into Marketo has the comma and .00

messier_1-1669812579320.png

messier_0-1669812523412.png

messier
Level 2

Re: Trying to get $ figure through velocity scripting... help?

WAIT, I got it. I knew it was user error! Thank you!

messier
Level 2

Re: Trying to get $ figure through velocity scripting... help?

Thanks @SanfordWhiteman  I appreciate the help, but it's still not rendering properly. I'm sure it's user error so I opened a ticket. 

SanfordWhiteman
Level 10 - Community Moderator

Re: Trying to get $ figure through velocity scripting... help?

You still haven't said what is rendering. And are you using real emails, not samples, to test?