1

In an email I have a variable coming in that is in string format (it's a price). I need to multiply that by another number, which means I need to convert the string to a number in the xx.xx format.

Does anyone know of an AMPScript function that will do this? I can't find one. Thank you!

1 Answer 1

2

AMPScript is loosely typed. You may want to utilize the AttributeValue() function so you can detect empty values in either number. Here's how I would do it:

%%[
var @price, @qty, @extPrice
/*
set @price = AttributeValue("price")
set @qty = AttributeValue("qty")
*/
set @price = "12.34"
set @qty = "3"

if empty(@price) or empty(@qty) then
  set @extPrice = "0.00"
else
  set @extPrice = multiply(@price,@qty)
endif

]%%
<br>extPrice: %%=formatNumber(@extPrice,D2)=%%

Output

extPrice: 37.02 

Reference

2
  • Thanks for the response! To clarify, the value I'll be receiving will be a number in the form of a string. I was understanding that Multiply will only work with an integer. Is there something in your code that I'm missing that will rectify this?
    – okc
    Commented Sep 30, 2016 at 16:55
  • When I say loosely typed, I mean AMPScript pretty much treats everything like a string. So if it looks like a string and isn't empty, then the Multiply() function should work. Commented Sep 30, 2016 at 16:57

You must log in to answer this question.

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