1 Reply Latest reply on Mar 13, 2017 9:05 AM by gkaiseril

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

    CalicoCat5000

      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?

        • 1. Re: $ sign, decimal places and thousand comma separator - resource guide?
          gkaiseril MVP & Adobe Community Professional

          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.