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

$ sign, decimal places and thousand comma separator - resource guide?

Explorer ,
Mar 13, 2017 Mar 13, 2017

Hi, could someone point me to a good resource with a list of adobe and/or javascript functions? 

I created a bunch of forms with fields using the Number selection from the Format tab and thought everything was fine, but have now realized that small rounding errors accumulate, and the end result might be wrong by one or two cents.

On the first form that I’m trying to correct, I have set the Format category to None, and now need to include the $ money sign, the comma separator, and two places after the decimal point.  From someone else’s post, in order to include two places after the decimal point, I’ve included in the Run Custom Validation Script:

  1. event.value = util.printf("%.2f", event.value);

Is this OK to use, or will this also create problems?

Is there a good resource of javascript syntax I could look at to figure out how to include decimal places, dollar signs and thousand comma separators?

TOPICS
Acrobat SDK and JavaScript
893
Translate
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
LEGEND ,
Mar 13, 2017 Mar 13, 2017
LATEST

It should be fine. If a problem does arise one could force the value of the field to a number by using the Number constrictor.

event.value = Number(util.printf("%.2f", event.value));

You will need to use some additional code if you want to do not want to display 0.00.

Your errors are caused by JavaScript using the IEEE 16 bit floating point convention and dealing with binary fractions. This is pretty common in all computer languages except many automatically adjust the decimal values to drop the small rounding errors.

The only reference for is the Acrobat JavaScript API Reference util.printf

There are other more sophisticated methods of rounding values than the printf method.

Translate
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