0

I have a data extension that gives me a user's currency, plus fields for the cost that look like this:

cost_USD | cost_EUR | cost_BRL

Here's what I have in my ampscript:

Set @partner_currency = partner_currency
Set @advertiser_email = advertiser_email
Set @variable_name = Concat('%%cost_',@partner_currency,'%%')

and within the body of the email:

%%=TreatAsContent(@variable_name)=%%

This works perfectly to retrieve the data under the cost_xxx fields, which are all numbers. However, I need to format each number according to the country as well.

I'm trying to format them using %%=FormatNumber(@variable_name,"N2","en-US")=%% but of course since @variable_name needs the "TreatAsContent" to return the number and not the string name of the variable name, the formatting isn't working.

Is there a way around this?

2 Answers 2

0

Try storing the value returned by TreatAsContent in a temporary var

Set @partner_currency = partner_currency
Set @advertiser_email = advertiser_email
Set @variable_name = Concat('%%cost_',@partner_currency,'%%')
Set @Temp = TreatAsContent(@variable_name)

Then call FormatNumber function on it:

%%=FormatNumber(@Temp,"N2","en-US")=%%
0

You can just place the FormatNumber around the TreatAsContent call.

%%=FormatNumber(TreatAsContent(@variable_name),"N2","en-US")=%%

Or inside of an AMPscript block:

%%[
   SET @cost = FormatNumber(TreatAsContent(@variable_name),"N2","en-US")
]%%

I also would recommend using the AttributeValue() function when returning your attributes/fields from the sendable data extension.

E.g.

Set @partner_currency = AttributeValue("partner_currency")
Set @advertiser_email = AttributeValue("advertiser_email")
Set @variable_name = Concat('%%cost_',@partner_currency,'%%')

AttributeValue() allows for null returns and helps with error handling. I highly recommend it for all personalization strings.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .