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

PDF form presenting incorrect value in Total

Explorer ,
Jul 30, 2023 Jul 30, 2023

I have made a simple invoice form that calculates the following

 

Weekly Fee is divided by 7 days = Daily Fee. Then Daily Fee is multiplied by the Billable Days to produce the Total.

 

In the example I am using the Weekly Fee = 692.71 which divided by 7 produces the Daily Fee = 98.96.

 

The amount of Billable Days is 31. Multiplying 31 x 98.86 should produce the Total = 3,067.76.

 

The problem I have is that the calculation in the form is showing as 3,067.72.

 

I believe this may be due to the calculation not rounding up or down correctly and I believe I may need some Javascript to adjust this-  but I have no idea how to achieve that.

 

If anyone can kindly assist with this it would be greatly appreciated. Thank you 🙂

TOPICS
JavaScript , PDF forms
1.5K
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 ,
Jul 30, 2023 Jul 30, 2023
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 ,
Jul 30, 2023 Jul 30, 2023

That's because 692.71 divided by 7 is not 98.96. It's 98.95857142857143, and when you multiply that by 31 you get 3067.7157142857145. If you want to get the results you've specified you need to actually round the numbers up or down. If you only do so using the Format setting of a Number field they would appear rounded, but won't actually be so. For actual rounding you need to use a 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
Explorer ,
Jul 30, 2023 Jul 30, 2023

Hi

 

Thank you for your response. That is what I suspected as I used a calculator to check and got the result you indicated.

 

However I am not sure what is it is you are suggesting that I do? This is the first form I have ever made using calculations.

 

How do I round it up or down? I have used the Format to display only 2 decimal points but if i switch that off and allow it to show all decimal places it still doesn't show the right total.

 

Apologies if I am being stupid 😉

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
Explorer ,
Jul 30, 2023 Jul 30, 2023

Sorry I just saw the comment about a script. Yes i thought i needed a script but how do I get this as I am not able to create Javascript.

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 ,
Jul 30, 2023 Jul 30, 2023

The easiest way to do it, without converting all of your calculations to JS, is to add the following as the custom Validation script of your fields:

 

event.value = event.value.toFixed(2);

 

And you shouldn't feel stupid. This is a common mistake made when people assume what they see on the page is the actual values of the fields, which doesn't have to be the case.

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
Explorer ,
Jul 30, 2023 Jul 30, 2023

ah thats great thanks. do i need to change any of the text in here to relate to my field names?

 

event.value = event.value.toFixed(2);

 

I added that into the validation section for the Daily Fee but nothing has happened. So i thought perhaps it should go in the Total field but it hasnt worked there either.

 

Thank you. I appreciate your time on this matter.

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 ,
Jul 30, 2023 Jul 30, 2023

No, you don't need to change anything.

Can you share the file in question?

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
Explorer ,
Jul 30, 2023 Jul 30, 2023

Sure here it is

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 ,
Jul 30, 2023 Jul 30, 2023

Here you go...

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
Explorer ,
Jul 30, 2023 Jul 30, 2023
LATEST

Ah!! Wonderful. True expert level assistance 🙂

Thank you very much for your efforts. I would never have figured that out!!

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