Copy link to clipboard
Copied
Hello,
I am preparing a form for our shipping department and I have it set up to calculate taxes, palletizing, etc and give a total. At first, it was giving me numbers with a bunch of decimal places like $37.555555557778 so I set the format to number and 2 decimals. It also makes an unwanted zero appear in that space even though no data has been entered yet. How can I fix this? I want my calculations to remain the same and for the numbers to only display 2 decimal places but I don't want the zero there because we sometimes have to fill out the form manually. I have very little experience with java script, I read up on some things but they do not make any sense to me. If there is a flat out formula you know that I can just copy and paste to the custom format box that achieves this, please just let me know. I greatly appreciate any help and thank you for your time.
Copy link to clipboard
Copied
You should know that the Format setting does not change the field's actual value, just the way it is displayed.
So if you add up two fields whose values are 2.555555557778 and 3.555555557778 (but they show 2.56 and 3.56), the result will be 6.111111115556, which would show up as 6.10. So if this is critical for you then you need to actually round them, using a script. This will also allow you to easily replace zero value with nothing.
Here's an example:
var v1 = Number(this.getField("Field1").valueAsString);
var v2 = Number(this.getField("Field2").valueAsString);
var total = v1+v2;
if (total==0) event.value = "";
else event.value = total.toFixed(2);
Copy link to clipboard
Copied
I am completely lost ... do I change it to custom format and then enter the entire script you wrote? Do I stop using the calculate function? Does "Field One" need to be changed to the first field in the calculation using the name I designated? Same for "Field Two" ?
Copy link to clipboard
Copied
You should change the custom Format of the fields to None and make sure they have the correct value using a calculation script, like the one I provided.
Yes, replace "Field1" and "Field2" with the actual field names in your file that you want to add up.