Copy link to clipboard
Copied
I have a long custom calculation script that combines 23 fields. Below is a small portion of the results and a small portion of the script I’m using. I have been successful with value.toFixed(2) to shorten to 2 decimal places. I’ve been successful with the line splits using \n.
Now, I am trying to format the dollar amounts with a comma separating thousands and hundreds if applicable.
Any assistance would be helpful!
Portion of script:
event.value = "Traveler 1 Name: " + this.getField("Traveler1Name").value + "\nConference Registration $ " + this.getField("ConfRegFeeT1").value.toFixed(2) +
"\nLodging $ " + this.getField("HotelCostT1").value.toFixed(2) + " X " + this.getField("HotelNightsT1").value.toFixed(2) + " = $ " + this.getField("HotelTotalT1").value. toFixed(2) +
"\nMeals: Breakfast $ " + this.getField("BreakfastCostT1").value.toFixed(2) + " X " + this.getField("BreakfastDaysT1").value.toFixed(2) + " = $ " + this.getField("BreakfastTotalT1").value.toFixed(2) +
"\nMeals: Dinner $ " + this.getField("DinnerCostT1").value.toFixed(2) + " X " + this.getField("DinnerDaysT1").value.toFixed(2) + " = $ " + this.getField("DinnerTotalT1").value.toFixed(2)
Results:
Any assistance would be helpful!
THANKS!
Copy link to clipboard
Copied
The util.printf function returns a string. So it's used anywhere a formatted number is needed. Basically, where you've used "toFixed" function.
For example:
util.printf("$%,02.2f", this.getField("BreakfastCostT1").value)
This returns a number prefixed with "$" and formated to use a comma as a 10^3 separator with 2 decimal places. Use it instead of ".toFixed()"
Copy link to clipboard
Copied
Use the number formatting function, util.printf().
Here's the reference entry:
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#printf
Copy link to clipboard
Copied
Thom, I saw that option suggested in some other questions on the forum, but am unsure how to use in this particular instance. What part of my script would be replaced with the util.printf(), or where would I it?
I am pretty new to this and know it isn't a pretty script, but sure appreciate your help!
Copy link to clipboard
Copied
The util.printf function returns a string. So it's used anywhere a formatted number is needed. Basically, where you've used "toFixed" function.
For example:
util.printf("$%,02.2f", this.getField("BreakfastCostT1").value)
This returns a number prefixed with "$" and formated to use a comma as a 10^3 separator with 2 decimal places. Use it instead of ".toFixed()"
Copy link to clipboard
Copied
THANK YOU!!!!! I believe this will work! This whole project has been just beyond my reach and I've spent the last few months learning from all of you! Thanks!
Now for the find/replace in my scripts!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now