Skip to main content
Inspiring
February 3, 2022
Answered

rounddown for a calculation

  • February 3, 2022
  • 2 replies
  • 2612 views

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!

This topic has been closed for replies.
Correct answer Thom Parker

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. 

 

 

2 replies

Nesa Nurani
Community Expert
Community Expert
February 3, 2022

You have error in your script, f in this.getfield need to be capital: this.getField.

To round down you can use Math.floor().

 

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
February 3, 2022

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. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
February 4, 2022

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!

 

Thom Parker
Community Expert
Community Expert
February 3, 2022

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?

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
February 3, 2022

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?