Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards
SOLVED

How can i format numbers in Campaign Classic?

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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/

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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/

Avatar

Level 1

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 !