Copy link to clipboard
Copied
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 🙂
Copy link to clipboard
Copied
Here you go...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 😉
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
No, you don't need to change anything.
Can you share the file in question?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Ah!! Wonderful. True expert level assistance 🙂
Thank you very much for your efforts. I would never have figured that out!!