Expand my Community achievements bar.

Adobe Campaign User Groups are live now. Join our Adobe Campaign User Groups and connect with your local leaders!

Format vars.recCount value for an alert?

Avatar

Level 5

I'm using JS to formt values. Insted of 1000, I would like it to be 1,000 on the final alert sent to the imbox of users.

I've found this formatter func online, but it is giving me errors:

const formatter = new Intl.NumberFormat('undefined', {
style: 'currency',
currency: 'USD',

// These options are needed to round to whole numbers if that's what you want.
//minimumFractionDigits: 0, // (this suffices for whole numbers, but will print 2500.10 as $2,500.1)
//maximumFractionDigits: 0, // (causes 2500.99 to be printed as $2,501)
});

vars.field1 = formatter.format(vars.recCount)); /* $2,500.00 */


Why?

09/03/2024 5:11:37 PM SCR-160032 Javascript: error while compiling script 'WKF41027/js'.
09/03/2024 5:11:37 PM JST-310000 Error while compiling script 'WKF41027/js' line 11: missing ; before statement (line='vars.field1 = formatter.format(vars.recCount)); /* $2,500.00 */ ' token='); /* $2,500.00 */ ').

The code uses currency, but I'd like just render this as numbers.

This is the alert sent as an email:

Hoy <%= formatDate(new Date(), "%2D/%2M/%4Y") %> , la cantidad de recipients con email comercial es:  <%= vars.field1 %>    y la cantidad de celular comerciales es <%= vars.field2 %> .


1 Reply

Avatar

Community Advisor

Hello @ogonzalesdiaz  You can use this code:

function addThousandSeparator(number_as_string) {  
  let parts = number_as_string.split('.');
  let integerPart = parts[0];
  let decimalPart = parts.length > 1 ? '.' + parts[1] : '';   
  integerPart = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ','); 
  return integerPart + decimalPart;
}

 

You can use it like this:

addThousandSeparator(vars.recCount);

     Manoj
     Find me on LinkedIn