Tuesday, July 06, 2021

AMPscript: Quickly Calculate Integers in SFMC / ExactTarget

There's no integer function in SFMC, but you can get there quickly with mod and subtract.

As a reminder:

mod(a,b) = remainder of a divided by b

subtract(c,d) = c minus d

So....

mod(5.5,1) 
= remainder of 5.5 divided by 1
= remainder of 5.5
= 0.5

subtract(5.5,mod(5.5,1))
= 5.5 minus remainder of 5.5 divided by 1
= 5.5 minus remainder of 5.5
= 5.5 minus 0.5
= 5

So....

if your non-integer number is @numOriginal, your calculation 

set @numInteger = subtract(@numOriginal,mod(@numOriginal,1))

That's one fun secret... here's another: there are far more Email Marketing Jobs than there are people like us to do the work. Your next job may be waiting at emailmktgjobs.blogspot.com.

No comments: