Skip to main content

I have an automation that is using a script I found on the message boards to format numeric values to currency. It works great. I pull the value from the script into the body of an email automation. However, when there is no value in the field I am using instead of showing nothing in the body of the email it shows 0.00

Below is the script being used. If amount to send in USD for Email is blank how can I suppress the 0.00 from showing in the variable placeholder in the body of the email?

 

 
let inputValues = input.config();
let currency = inputValues.currency;

//define function to convert numbers to currencies for report display
function toCurrency(rawValue) {
    return  (Number(rawValue)).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
}

output.set("amount to send in USD for Email", toCurrency(currency));

Try:

let inputValues = input.config();

let currency = inputValues.currency;



//define function to convert numbers to currencies for report display

function toCurrency(rawValue) {

return (Number(rawValue)).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');

}





if(currency){

output.set("amount to send in USD for Email", toCurrency(currency));

}

else{

output.set("amount to send in USD for Email", "");

}

Try:

let inputValues = input.config();

let currency = inputValues.currency;



//define function to convert numbers to currencies for report display

function toCurrency(rawValue) {

return (Number(rawValue)).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');

}





if(currency){

output.set("amount to send in USD for Email", toCurrency(currency));

}

else{

output.set("amount to send in USD for Email", "");

}

Thanks! That is what we needed. Appreciate your input!


Reply