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

Calculation is Throwing an Error

Community Beginner ,
Jun 01, 2020 Jun 01, 2020

I am making a simple form to take a contract amount, less payment already received, less this payment should total the balance due.  When I do the calculation ContractAmount0 - PaymentReceived0 - ThisPayment0 is giving this error:  The value entered does not match the format of the field [BalDue0].  

Everything is set to number, 2 decimal places, with the $ symbol.  It's rounding somehow.  

TOPICS
PDF forms
1.4K
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
1 ACCEPTED SOLUTION
Community Expert ,
Jun 01, 2020 Jun 01, 2020

You have hit a very interesting artifact of number representation in Acrobat. This is actually quite rare.

The value should be zero, but the first subtraction yields ".93999999994" instead of ".94".  So the next subtraction, instead of going to zero, converts the calculation into scientific notation.  The built-in formatting should just convert this to zero, but it wasn't built to handle it, so displays the errror.

 

The solution is to use your own formatting script. This will work.

 

event.value = util.printf("$%,0.2f",event.value);

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

View solution in original post

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
Community Expert ,
Jun 01, 2020 Jun 01, 2020

Is the value of all of those fields a number? No other characters?

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
Community Beginner ,
Jun 01, 2020 Jun 01, 2020

Just a decimal is included.

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
Community Expert ,
Jun 01, 2020 Jun 01, 2020

Can you share the actual file with us?

You can attach it to the original message using the tiny paperclip icon at the bottom when you edit it, or upload it to a file-sharing website (like Dropbox, Google Drive, Adobe Cloud, etc.), generate a share link and then post it here.

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
Community Expert ,
Jun 01, 2020 Jun 01, 2020

You have hit a very interesting artifact of number representation in Acrobat. This is actually quite rare.

The value should be zero, but the first subtraction yields ".93999999994" instead of ".94".  So the next subtraction, instead of going to zero, converts the calculation into scientific notation.  The built-in formatting should just convert this to zero, but it wasn't built to handle it, so displays the errror.

 

The solution is to use your own formatting script. This will work.

 

event.value = util.printf("$%,0.2f",event.value);

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

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
Community Beginner ,
Jun 01, 2020 Jun 01, 2020

Thank you for figuring this out, but this may be a dumb question, but where do I put event.value = util.printf("$%,0.2f",event.value); does it go into the custom calculation script?

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
Community Expert ,
Jun 01, 2020 Jun 01, 2020

No, it goes into the Custom Format Script. 

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

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
Community Beginner ,
Jun 01, 2020 Jun 01, 2020
LATEST

Thank you!!  That did work! I appreciate your help!

 

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
Community Expert ,
Jun 01, 2020 Jun 01, 2020

What does you get when you set the format to None.

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