• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

HOW TO ADD COMMA IN A CALCULATED FIELD

Community Beginner ,
Aug 03, 2021 Aug 03, 2021

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.

 

kmbt345_0-1628041329984.png

kmbt345_1-1628041362396.png

kmbt345_2-1628041496881.png

 

 

TOPICS
Create PDFs , Edit and convert PDFs , General troubleshooting , How to , JavaScript , PDF forms

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Aug 03, 2021 Aug 03, 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(".");

Votes

Translate

Translate
Community Expert , Jan 13, 2022 Jan 13, 2022

Use this code as the custom format script. 

 

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

 

 

Votes

Translate

Translate
Community Expert ,
Aug 03, 2021 Aug 03, 2021

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 04, 2021 Aug 04, 2021

Copy link to clipboard

Copied

It worked. Thank you very much.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 13, 2022 Jan 13, 2022

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.

kmbt345_0-1642127133882.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

LATEST

Use this code as the custom format script. 

 

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

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines