Format vars.recCount value for an alert? | Community
Skip to main content
Level 6
September 3, 2024
Solved

Format vars.recCount value for an alert?

  • September 3, 2024
  • 2 replies
  • 956 views

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 %> .


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 Manoj_Kumar

Hello @god_prophet  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);

2 replies

Manoj_Kumar
Community Advisor
Manoj_KumarCommunity AdvisorAccepted solution
Community Advisor
September 4, 2024

Hello @god_prophet  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  | https://themartech.pro
Level 6
September 4, 2024

Hi Manjo, got error: 09/04/2024 10:28:35 AM SCR-160032 Javascript&colon; error while compiling script 'WKF41xxx/js'.
09/04/2024 10:28:35 AM JST-310000 Error while compiling script 'WKF41xxx/js' line 3: missing ; before statement (line=' let parts = number_as_string.split('.'); ' token='parts = number_as_string.split('.'); ').

 



Manoj_Kumar
Community Advisor
Community Advisor
September 5, 2024

Hello @god_prophet  here is the simplified version

 

function addThousandSeparator(myCount) {
return myCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}

Manoj  | https://themartech.pro