Math operators in Velocity?

Ronnie_Duke2
Level 4

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.

pastedImage_1.png

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?

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

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.

Ronnie_Duke2
Level 4

Re: Math operators in Velocity?

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

Thanks!

Travis_Schwartz
Level 4

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.

SanfordWhiteman
Level 10 - Community Moderator

Re: Math operators in Velocity?

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