How can i format numbers in Campaign Classic? | Community
Skip to main content
Level 2
October 6, 2023
Solved

How can i format numbers in Campaign Classic?

  • October 6, 2023
  • 1 reply
  • 1453 views

Hi!

I have some issues with a variable that i want to use in my html as part of the personalization.

 

Nowadays, the variable is like this: TotalAmount: 12561.2

But i would like to transform it into something like this: 1.2561,20

 

Do you know how can i do it? I hope the answer is easy to apply. My first thought was using the "edit an expression" wizard but i didnt find the way.

 

Thank you

🙂

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Marcel_Szimonisz

Hello @javi_landa,

for personalization you can use power of JavaScript so you can format number eg by following script:

 

function formatNumberWithCommas(number) { // Split the number into integer and decimal parts (if any) var parts = number.toString().split("."), integerPart = parts[0], decimalPart = parts[1] || ""; // Add commas to the integer part var formattedIntegerPart = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ","); // Combine the integer and decimal parts if (decimalPart) { return formattedIntegerPart + "." + decimalPart; } else { return formattedIntegerPart; } } // Example usage: const numberWithCommas = formatNumberWithCommas(1234567.89); <%=numberWithCommas%>; // Output: "1,234,567.89"

 

 

 

 

Marcel Szimonisz

MarTech Consultant
for more tips visit my blog
https://www.martechnotes.com/

1 reply

Marcel_Szimonisz
Community Advisor
Marcel_SzimoniszCommunity AdvisorAccepted solution
Community Advisor
October 6, 2023

Hello @javi_landa,

for personalization you can use power of JavaScript so you can format number eg by following script:

 

function formatNumberWithCommas(number) { // Split the number into integer and decimal parts (if any) var parts = number.toString().split("."), integerPart = parts[0], decimalPart = parts[1] || ""; // Add commas to the integer part var formattedIntegerPart = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ","); // Combine the integer and decimal parts if (decimalPart) { return formattedIntegerPart + "." + decimalPart; } else { return formattedIntegerPart; } } // Example usage: const numberWithCommas = formatNumberWithCommas(1234567.89); <%=numberWithCommas%>; // Output: "1,234,567.89"

 

 

 

 

Marcel Szimonisz

MarTech Consultant
for more tips visit my blog
https://www.martechnotes.com/

January 24, 2024

I'm trying to find how to integrate that formula into the workflow but I'm not finding anything in the documentation.

 

Can you please explaing how to use it with more detail?

 

Thanks on advise !