Copy link to clipboard
Copied
I need some help creating a formula for rounding down a field in a form I'm creating. I need the field to take the numbers from 2 separate fields and add them together subtract 10 and then divide by 2.
Something like (Field1+Field2-10)/2 and then round down to the nearest whole number so 4.5 goes to 4 and so on.
Also I dont know if it would work differently but if it does i need it to work with negative numbers so -3.5 rounds to 4
If anyone could help me with this i would be very appreciative.
Try this code as the field's custom calculation script:
var result = ((Number(this.getField("Field1").value)+Number(this.getField("Field2").value))-10)/2;
event.value = Math.round(Math.abs(result));
Copy link to clipboard
Copied
Try this code as the field's custom calculation script:
var result = ((Number(this.getField("Field1").value)+Number(this.getField("Field2").value))-10)/2;
event.value = Math.round(Math.abs(result));
Copy link to clipboard
Copied
This kinda works, is there a way to make it work for negative numbers, like -3.5 to -4
Thanks btw for the help.
Copy link to clipboard
Copied
That is more tricky because by default the rounds negative numbers that end with .5 down, while positive numbers get rounded up... You will need to use a custom rounding function to do that.
And to keep the negative numbers negative just remove the Math.abs() part of the code I posted above.
Copy link to clipboard
Copied
Or did you mean that -3.5 rounds to -4?
Copy link to clipboard
Copied
Yes, so -3.5 to -4
Copy link to clipboard
Copied
You might have to use the Math.floor method and not the Math.round method.
Copy link to clipboard
Copied
That would work, but it would round down any number... So 3.99 will become 3.0. I'm not sure that's what the OP is after.
Copy link to clipboard
Copied
Worked out perfectly, thanks for all the help guys.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now