Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Form which calculates square root of one field times a second field rounded up to a value

Community Beginner ,
Dec 02, 2021 Dec 02, 2021

I am trying to convert an excel spreadsheet to a fillable PDF form.  The sheet has the following equation to calculate a value with a certain number of significant figures and then round up to a given unit.  

CEILING(ROUNDUP($H$15*SQRT($H$18),2),$H$16))

I want to create a similar JAVA script of a field on the form "uncertainty" from the fields as follows:

H15=Ub

H18=Number

H16=dvalue

 

Any assistance would be greatly appreciated

TOPICS
How to , JavaScript , PDF forms
780
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 02, 2021 Dec 02, 2021

First of all, it's JavaScript, not Java.

- The square root of a number can be calculated like this:

Math.sqrt(x)

- There's no built-in command in JS that allows to round up to a specific number of digits, but you can create your own function that will do it.

- Rounding up to the nearest integer can be done like this:

Math.ceil(x)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 02, 2021 Dec 02, 2021

Thank you for your prompt response, as you can see I am not very familiar with javascript (note my inserting a space between Java and script in the initial post).  

What would the resulting script look like to take the square root of the value in field "number" and multiply it by the value in "Ub" with the Math ceiling of the value in the field "dvalue"?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 02, 2021 Dec 02, 2021

Sorry, I see now that the CEILING function in Excel also takes a parameter to round up to a specific multiple.

That doesn't exist in JS as a built-in function, either. You'll need to create your own formula to do it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 03, 2021 Dec 03, 2021
LATEST

I have been trying to find a solution to this and found a post from George Kaiser in the old Forums which looks like something simlar.  Hoping someone can look at the script he provided and offer assistance in using the Math.pow and math.ceil functions to round a number up a given incriment.  For example round up to the next interval of 0.4 so a value entered as 1.3 would round up to 1.4, or a value entered as 1.5 would round up to 1.8.

 

Here is the Code George Provided on the forum (https://acrobatusers.com/forum/forms-acrobat/rounding-acrobat/)

 

// get value of field to round up
var nValue = this.getField("Submit.1").value;
// value for adjusting the precision, decimal point.
var nPrecision = -3;
// adjust sign of nPrecision for exponentiation
nPrecsision = -nPrecision;
// compute the needed decimal adjustment
var nAdjustment = Math.pow(10, nPrecision);
// adjust the decimal point
nValue = nValue * nAdjustment;
// rounded up value
nValue = Math.ceil(nValue);
// restore the original decimal point location and display the result
event.value = nValue / nAdjustment;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines