Copy link to clipboard
Copied
Hi,
I want't to add a comma to my calculated field. Here's my case, I have summed a column but got a result of Php 34999.89 instead of a number with comma (Php 34,999.89). I can't edit the formatting becuase I already added a custom format script. Can you help me with my script or do you have other ideas how to do this? Please see attached picture for reference. Thank you.
Try this code:
var x = event.value;
var n = x.toString().split(".");
n[0] = n[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
if(event.value == 0) event.value = "";
else event.value = "Php "+ n.join(".");
Use this code as the custom format script.
event.value = util.printf("PHP %,02.2f",event.value);
Copy link to clipboard
Copied
Try this code:
var x = event.value;
var n = x.toString().split(".");
n[0] = n[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
if(event.value == 0) event.value = "";
else event.value = "Php "+ n.join(".");
Copy link to clipboard
Copied
It worked. Thank you very much.
Copy link to clipboard
Copied
Hello,
Just a follow-up question on this code. There are times or most of the time when I use this code the result would have 3 or more decimal places. Is there a way where the result would be fixed to 2 decimal places? Thank you.
Copy link to clipboard
Copied
Use this code as the custom format script.
event.value = util.printf("PHP %,02.2f",event.value);