- Marketing Nation
- :
- Products
- :
- Product Discussions
- :
- Math operators in Velocity?

Your Achievements

Next /

Sign inSign in to Community to gain points, level up, and earn exciting badges like the new Applaud 5 BadgeLearn more!

View All BadgesSign in to view all badges
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-14-2019
03:12 PM

10-14-2019
03:12 PM

Math operators in Velocity?

Hello all,

Has anyone tried using basic math operators in Velocity in Marketo? The documentation says I should be able to use simple arithmetic in my variables, but for some reason they do not work in Marketo.

I am trying to take take number fields and convert them to percentages for calculations in my email:

`#set( $test = ${lead.Some_Number_Field__c} / 100 ) `

However when I try to output ${test} it just outputs the variable in the email instead of the result.

I've found that if I use the Velocity **$math** function, I can get it to work, but it's just so tedious for simple operations:

`#set( $test = $math.div(${lead.Some_Number_Field__c},100 )) `

The above code does output a correct percentage (i.e. 35 => 0.35)

Anyone else have this experience?

Labels:

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-14-2019
03:21 PM

10-14-2019
03:21 PM

Re: Math operators in Velocity?

Your curly braces are unnecessary.

But always use the MathTool methods, not operators, b/c the parser will fail (noisily or silently) in some cases, which is... bad.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-14-2019
03:58 PM

10-14-2019
03:58 PM

Re: Math operators in Velocity?

ah, so using the long form, while tedious, sounds like the best way to do it after all 🙂

Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

11-29-2019
01:47 PM

11-29-2019
01:47 PM

Re: Math operators in Velocity?

I'm hoping I can get a little help with something related.

essentially I am trying to reduce a specific rate (it's a token) by either .25 or .50. doing some research I found the following to plug in:

$math.sub($lead.autoPreApprovalNewRate, ".25")

and

$math.sub($lead.autoPreApprovalNewRate, ".50")

and that worked like a charm... except for I have one email that is not rendering the .25 token and is displaying the code instead. Am I missing something? why does it work for some emails, yet not others?

Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

11-29-2019
02:04 PM

11-29-2019
02:04 PM

Re: Math operators in Velocity?

Please open a new thread, as this one's done, and highlight your code using the Syntax Highlighter.