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

Combining text and number fields without loosing number field format.

Community Beginner ,
Aug 20, 2020 Aug 20, 2020

Copy link to clipboard

Copied

In my job function I have to combine fields to generate letters for different departments. I can usually cobble together a working form, but in this case I'm hitting a wall. I'm trying to combine a text field with a number field without loosing my number field formatting.

 

Example: The following results in "The cost is 1000" while I am trying to get "The cost is $1,000.00"

var cost = "The cost is ";
var OS = this.getField("Old Salary").value

event.value = cost + OS;

 

 

TOPICS
Acrobat SDK and JavaScript

Views

847

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 20, 2020 Aug 20, 2020

If this is just to display an output (not to be calculated any further with other fields), then You can use custom calculation script with arbitraty mask using the "util.printx()" method

 

Use it like this :

 

var v = this.getField("Old Salary").value;
v = util.printx("$9,9999", v);
event.value = "The cost is " +v;

Votes

Translate

Translate
Community Expert , Aug 21, 2020 Aug 21, 2020

Just move comma from this $9,9999 to this $99,999 but be warned then it won't show 1,000 it will show 10,00

 

EDIT: If you want to show both 1,000 and 10,000 replace this line: v = util.printx("$9,9999", v);

with this: v = util.printf("$%,0.0f", v);

If you also want to add decimal,replace second zero with number of desired decimals.

 

Votes

Translate

Translate
Community Expert ,
Aug 20, 2020 Aug 20, 2020

Copy link to clipboard

Copied

If this is just to display an output (not to be calculated any further with other fields), then You can use custom calculation script with arbitraty mask using the "util.printx()" method

 

Use it like this :

 

var v = this.getField("Old Salary").value;
v = util.printx("$9,9999", v);
event.value = "The cost is " +v;

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 21, 2020 Aug 21, 2020

Copy link to clipboard

Copied

This is great! Is there a way to format it if the number of digits isn't fixed? In the above example the "$10,000" comes out as "$1,0000".

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 ,
Aug 21, 2020 Aug 21, 2020

Copy link to clipboard

Copied

Just move comma from this $9,9999 to this $99,999 but be warned then it won't show 1,000 it will show 10,00

 

EDIT: If you want to show both 1,000 and 10,000 replace this line: v = util.printx("$9,9999", v);

with this: v = util.printf("$%,0.0f", v);

If you also want to add decimal,replace second zero with number of desired decimals.

 

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 21, 2020 Aug 21, 2020

Copy link to clipboard

Copied

This worked exactly as I wanted. Thanks!

 

var v = this.getField("Old Salary").value;
v = util.printf("$%,0.2f", v);
event.value = "The cost is " + v;

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 ,
Aug 21, 2020 Aug 21, 2020

Copy link to clipboard

Copied

LATEST

Hey Jason!

 

Glad that this helped. Don't forget to mark NesaNurani's answer as correct solution, thank you.

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