Skip to main content
deleted 21 characters in body
Source Link
Adam Spriggs
  • 31.1k
  • 6
  • 44
  • 88

AMPScript is loosely typed. You may want to utilize the AttributeValue() functionsAttributeValue() function so you can detect empty values in either number (using the empty() function). Here's how I would do to 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

AMPScript is loosely typed. You may want to utilize the AttributeValue() functions so you can detect empty values in either number (using the empty() function). Here's how do to 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

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

Source Link
Adam Spriggs
  • 31.1k
  • 6
  • 44
  • 88

AMPScript is loosely typed. You may want to utilize the AttributeValue() functions so you can detect empty values in either number (using the empty() function). Here's how do to 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