Copy link to clipboard
Copied
ok after 2hrs of trying to research and trial and error ive come back to the community to help me out please. trying to get a number rounded down using custom calc. my formula is:
var v1 = this.getfield("STR"); var v2 = this.getfield("StrItem"); var v3 = this.getfield("RageStrMod"); event.value = roundDown((v1 + v2 /2)+ v3);ive tried other formulas but nothing seems to work. any help is appriciated!
Copy link to clipboard
Copied
Thank you Nesa, I was a little fast on my update. Just copying the code. Note that the code also does not correct for non-numerical inputs, but that's a different topic.
Here's the correction:
var v1 = this.getField("STR").value;
var v2 = this.getField("StrItem").value;
var v3 = this.getField("RageStrMod").value;
event.value = Math.floor((v1 + v2 /2)+ v3);
The Math.floor() function doesn't actually "round down" it simply removes any decimal value. There's no such thing as rounding up or down. There's just rounding. The "floor" and "ceiling" functions are just that, the floor or cieling of the decimal value.
Copy link to clipboard
Copied
The actual field values are missing from the calculation script.
Here's the fixed code
var v1 = this.getfield("STR").value;
var v2 = this.getfield("StrItem").value;
var v3 = this.getfield("RageStrMod").value;
event.value = roundDown((v1 + v2 /2)+ v3);
There aren't any built-in functions named "roundDown". So I'm assuming that you have created this function yourself?
Copy link to clipboard
Copied
thank you and no i was going off of https://helpx.adobe.com/sign/using/calculated-fields.html# under supported functions?
its part of official adobe website. but it's not working. is there a way to create a function to round down?
Copy link to clipboard
Copied
You have error in your script, f in this.getfield need to be capital: this.getField.
To round down you can use Math.floor().
Copy link to clipboard
Copied
Thank you Nesa, I was a little fast on my update. Just copying the code. Note that the code also does not correct for non-numerical inputs, but that's a different topic.
Here's the correction:
var v1 = this.getField("STR").value;
var v2 = this.getField("StrItem").value;
var v3 = this.getField("RageStrMod").value;
event.value = Math.floor((v1 + v2 /2)+ v3);
The Math.floor() function doesn't actually "round down" it simply removes any decimal value. There's no such thing as rounding up or down. There's just rounding. The "floor" and "ceiling" functions are just that, the floor or cieling of the decimal value.
Copy link to clipboard
Copied
PERFECT! thank you so much! the math was off a lil had to put another () to add before dividing but thats my bad. again thank you tons!
Copy link to clipboard
Copied
The Math.floor() function doesn't actually "round down" it simply removes any decimal value.
By @Thom Parker
Actually you are wrong there, Math.trunc() (which i belive is not supported in acrobat) would be for removing decimals, Math.floor() does round down to nearest integer.
Copy link to clipboard
Copied
True, the Math.trunc function specifically removes the decimal portion of a number, but that doesn't mean Math.floor rounds down. It doesn't. The floor function returns the next smallest integer. Which is literally the same thing as truncating for positive decimals.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more