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 %> .
Solved! Go to Solution.
Views
Replies
Total Likes
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);
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);
Hi Manjo, got error: 09/04/2024 10:28:35 AM SCR-160032 Javascript: 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('.'); ').
Views
Replies
Total Likes
Hello @god_prophet here is the simplified version
function addThousandSeparator(myCount) {
return myCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
Views
Replies
Total Likes
My ACC instance only works with legacy JS.
So, this code did work:
function addThousandSeparator(number_as_string) {
var parts = number_as_string.split('.');
var integerPart = parts[0];
var decimalPart = parts.length > 1 ? '.' + parts[1] : '';
integerPart = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return integerPart + decimalPart;
}
vars.field1 = addThousandSeparator(String(vars.recCount));
Views
Replies
Total Likes
Hello @god_prophet ,
You can refer this post - https://experienceleaguecommunities.adobe.com/t5/adobe-campaign-classic-questions/how-can-i-format-n...
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies