Copy link to clipboard
Copied
Hello,
This is my first time attempting to write a formula in a fillabe pdf. I've created fillable forms before but this time would like people to be able to enter scores and for the scores to calculate across and then the those totals be calculated down. I've attached a copy of what the form itself looks as well as the fields I've entered in the form so far. I've entered the following formula in the Simplified field notation on the Calculation tab:
(MBR1Q1+MBR2Q1+MBR3Q1)/3
I want to make this automatically round to the nearest hundredths. Any and all assistance is greatly appreciated. Thanks.
Copy link to clipboard
Copied
If all you want to do is display the rounded value, then use the built-in formatting.
If the actual value needs to be rounded, then you'll to uses script to modify the actual value.
It is up to you.
Let me elaborate. All fields have whats called an appearance. This is text and graphics that are visible to the user. But fields also have an underlying value. If the value of a field is to be used somewhere else, for example in a calculation, then you probably don't want it to be rounded. But people often want the value that is displayed to the user to be rounded, so it looks nice. This is what formatting is about. Formatting only affects the appearance.
Copy link to clipboard
Copied
Hi,
Just right-click on the total text field >>>>Properties>>>> and go to the "Format" tab.
From the dropdown menu provided select "Number".
You'll notice that as soon as you select this option, you will get access to how many decimal spaces you want to the right of the period.
Selecting "0" will allow the rounding of this number to the nearest hundredth.
If this is not what you want to do then you can add a custom format javascript for this field. to control this rounding.
Copy link to clipboard
Copied
This is NOT rounding. Setting the Format setting of the field doesn't change its actual value, just the value that is displayed. If the result is 1.5 and you set it to show zero decimals it will show as "2", but if you then multiply the value of that field by 2 it will result in 3, not 4.
To really round the value of the script you would need to use a script.
Copy link to clipboard
Copied
You're right Try67.
Thank you for clarifying as usual.
It visually rounds it but when you click on the field it displays the real value.
Ok, so onlyonekj,
in that case, you can leave your simplified notation, but open the properties on that calculated field again and click on the "Format" tab.
Select custom, and click on the Edit button for the Custom Format Script section.
You can use a very simple custom format script like this:
var v = Math.abs(+getField("myField").value/100)*100;
event.value = (s.toFixed(2);
Copy link to clipboard
Copied
This also does not round the value.
The Format script only changes the appearane of the field value. It does not change the value itself.
Do you really need the value rounded? or is this only for display?
Copy link to clipboard
Copied
Thank you also Thom for clarifying this.
I tried Math.round and Math.ceil.
I used a calculator to compare the results from the javascript.
I entered in one field 3.65 and in another 4.71 and then multiply them.
Using a calculator it equals 17.1915
In javascript, using Math.round for the whole equation rounds up the number to 18.
While using Math.ceil rounds it up to 17.
Using Math.abs by itself displays the whole real value. Way too big number.
What do yo recommend?
I don't know how to work around this.
Copy link to clipboard
Copied
Thom,
What I want it to do is:
Ex1: 25 + 26+ 25/3= 25.333333333333; I want 25.33 to show for answers like this.
Ex2: 28 + 25 + 30/3= 27.66666666667; I want it to show 27.67
Ex3: 3.5 + 3 + 3/3= 3.166666666666667; I want it to show 3.17
Ex4: 20.33 + 30.33 + 60.33/3= 36.9966666666666; I want it to show 37
I hope this explanantion helps.
Copy link to clipboard
Copied
If you need it just for display like Thom asked, the script that I posted for you works. Did you even try it?
I admit I am learning javascript but damn...
This is really not that hard and it doesn't require an Adobe ACP or an MVP to say something like it could be done diffrently or more elegantly and get away with the correct answer.
Try it (both of you) and if it works that is the solution.
If you need these fields to be rounded accurately, there is a lot more involved which is where I am stuck learning at this time.
However, if you need that total to be calculated further with another field, and you you need the rounding to be precise, you can work around it with using valueAsString instead of the real value.
I am not using any website, no Adobe SDK, not stealing the idea from anyone by the way.
That script is just demosntrating simple 6th grader pre-algebra see here: https://www.khanacademy.org/math/pre-algebra/pre-algebra-decimals/pre-algebra-rounding-decimals/v/ro....
Copy link to clipboard
Copied
Is_rbls,
Thank you for your assistance. I came to the community to get some assistance because I am very new to trying to write forumlas in Adobe. When I read the replies, before trying your suggestions, I went ahead and replied to Thom showing him what I was looking for. My apologies if I offended you by not trying your solution before commenting. I am at work and was checking my replies during my break. I definitely plan to try everyone's suggestions. I love to have more than one way to solve these types things.
Again, thank you for your assistance and my apologies...I kind of feel bad for asking the question now that I know it's on a 6th grade level. I just truly did not know how to do it.
Copy link to clipboard
Copied
No, please don't apologize. My reaction wasn't really aimed at you.
I am also new to javascript and new to the forums, but I am not new to computing and networking.
I was frustrated, because a lot of times in these forums I say something first and then like 3 different people with their big badges come and say something different just to police me up. At the end of the thread someone just repeats the same thing I said and gets the answer.
I've been filtered and watched closely since day one. So yes, it frustrates me a lot to see that other people get their answers marked as correct constantly,specially when I provide answers that I've referenced from other forums conversations to help another user.
Anyway, I don't want to make a stink about this.
I'm just venting and I do respect Thom a lot. I also follow him, but today I felt I needed to let it out.
My first reply to you was this:
"Just right-click on the total text field >>>>Properties>>>> and go to the "Format" tab. From the dropdown menu provided select "Number". You'll notice that as soon as you select this option, you will get access to how many decimal spaces you want to the right of the period. Selecting "0" will allow the rounding of this number to the nearest hundredth."
Then Try67 said:
This is NOT rounding. Setting the Format setting of the field doesn't change its actual value, just the value that is displayed. If the result is 1.5 and you set it to show zero decimals it will show as "2", but if you then multiply the value of that field by 2 it will result in 3, not 4.
To really round the value of the script you would need to use a script.
And so I thanked Try67 and provided you with the script. That's two out of two correct answers if we go by Thom's last answer:
This also does not round the value. The Format script only changes the appearane of the field value. It does not change the value itself. Do you really need the value rounded? or is this only for display?
AND, last he added this:
If all you want to do is display the rounded value, then use the built-in formatting.
If the actual value needs to be rounded, then you'll to uses script to modify the actual value.
It is up to you.
C'mon... can you see what I'm talking about? Maybe this sounds childish, but like I said, today I had enough of this.
Copy link to clipboard
Copied
If all you want to do is display the rounded value, then use the built-in formatting.
If the actual value needs to be rounded, then you'll to uses script to modify the actual value.
It is up to you.
Let me elaborate. All fields have whats called an appearance. This is text and graphics that are visible to the user. But fields also have an underlying value. If the value of a field is to be used somewhere else, for example in a calculation, then you probably don't want it to be rounded. But people often want the value that is displayed to the user to be rounded, so it looks nice. This is what formatting is about. Formatting only affects the appearance.
Copy link to clipboard
Copied
Thanks Thom. Is there something I need to do to close this post? I don't think I will be asking anything else. I truly appreciate your time.
Copy link to clipboard
Copied
Mark one of my answers as correct 😉
Copy link to clipboard
Copied
Ok...thanks.
Copy link to clipboard
Copied
I tried using this script in my fillable form PDF and I'm not having any luck.
This is the current script I have in the custom format to make it round to the 8th decimal. However when you select the cell after the calculation, it shows a number that is larger than 8 decimals.
if((event.value == 0) || isNaN(event.value) || (event.value== Infinity))
event.value = "";
else
event.value = util.printf("%0.8f",event.value);
Copy link to clipboard
Copied
Under what event did you place this code?
Copy link to clipboard
Copied
In the Custom Format Script, see the attached image. Thanks!
Copy link to clipboard
Copied
That doesn't affect the actual value of the field, only how it is displayed.
If you want to change the actual value move your code to the custom Validation event, or integrate it into a Calculation script, if the field has a calculated value.
Copy link to clipboard
Copied
This worked!!! Thank you!