Skip to main content
Participant
August 4, 2021
Answered

HOW TO ADD COMMA IN A CALCULATED FIELD

  • August 4, 2021
  • 1 reply
  • 1893 views

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.

 

 

 

Correct answer Thom Parker

Use this code as the custom format script. 

 

event.value = util.printf("PHP %,02.2f",event.value);

 

 

1 reply

Nesa Nurani
Community Expert
Community Expert
August 4, 2021

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(".");

kmbt 345Author
Participant
August 4, 2021

It worked. Thank you very much.