Copy link to clipboard
Copied
Hi, I'm trying to convert this excel formula to javascript:
=ROUND((0.007184*(E6)^0.725*(G6)^0.425),3-LEN(INT(0.007184*(E6)^0.725*(G6)^0.425)))
where E6 is a pdf field named Ht
G6 is a pdf field named Wt
any help would be very much appreciated.
Copy link to clipboard
Copied
All of the methods you need to use are described here:
General tutorial about calculations in Acrobat: https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations
Copy link to clipboard
Copied
Very helpful indeed! Thank you!
Copy link to clipboard
Copied
The problem with translating such an Excel formula is that the round function is different in JavaScript. I would solve the problem like this (the following assumes that there are never any negative results):
var E6 = this.getField("Ht").value;
var G6 = this.getField("Wt").value;
var v = Math.pow(0.007184 * E6, 0.725) * Math.pow( G6, 0.425);
if (v < 10.0) {
// round to two decimal places
event.value = Math.round(v * 100) / 100;
}
else if (v < 100.0) {
// round to one decimal
event.value = Math.round(v * 10) / 10;
}
else {
// round to the nearest integer
event.value = Math.round(v);
}
You would use this as your custom calculation script in your result field.
Copy link to clipboard
Copied
Yes the rounding was where I had trouble. This worked perfectly! Thank you!
Copy link to clipboard
Copied
I'm trying to take this a step further. I have a field named Dose1 with the following code:
var v = this.getField("BSA");
event.value = Math.round(v.value * 125);
I then have a field named AdjDose1 that defaults to 100. I want to make it so that when any number below 100 is entered, it takes that percentage of the result of Dose1 and displays the new result in Dose1 field. For example:
Dose1 displays 250.
80 is entered into AdjDose1.
Dose1 now displays 200.
Is it possible to do this?
Thank you very much indeed in advance.
Copy link to clipboard
Copied
If this is for human medications, you really need do better. At minimum you need to validate the input values and the calculated results.
Copy link to clipboard
Copied
Hi, yes I should clarify. I'm a pharmacist with 15 years of experience. I know I titled the thread Medication Order Form, however this form will be used as a tool to "double-check" separate, handwritten medication order forms. Nonetheless, the input values and custom calculations will be validated by two pharmacists other than myself.
Copy link to clipboard
Copied
OK. You can change the calculation script to:
var v = this.getField("BSA");
var AdjDose1 = getField("AdjDose1").value;
if (AdjDose1 < 100) {
event.value = Math.round(125 * v.value * AdjDose1 / 100);
} else {
event.value = Math.round(125 * v.value);
}
Copy link to clipboard
Copied
works perfectly. Thank You!!
Copy link to clipboard
Copied
I have just ONE last calculation based on the above I'm hoping you could help with.
I need Dose1 to be result of 1.4 * BSA. If the result is >2, I need it to display 2. If less than 2, I need the result to be rounded to two decimal places but no hanging zeros (ex: 1.9 but not 1.90). Then as above, if any value less than 100 is entered into AdjDose1, that percentage of Dose1 is displayed in Dose1. For example:
when BSA = 1.35
Dose1 = 1.4 * 1.35
Dose1 = 1.89
AdjDose1 = 50
Dose1 now displays 0.95
when BSA = 1.7
Dose1 = 1.4 * 1.7
Dose1 = 2
AdjDose1 = 50
Dose1 now displays 1
Many thanks in advance!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now