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!


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"
  set @extPrice = multiply(@price,@qty)

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


extPrice: 37.02 


  • 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 Sep 30 '16 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. – Adam Spriggs Sep 30 '16 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.