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

Excel to JavaScript

New Here ,
Mar 20, 2020 Mar 20, 2020

Hi! I need to convert the following excel formula to Javascript for my PDF, I've studied basic syntax a bit, but cant seem to figure it out. 

 

The excel formula is:

=IF(A15=1,B15*0.75,(A15-0.5)*B15)

 

However, in the PDF,  A15 will be Days1 and B15 will be MIE1 . 

 

Please Help

TOPICS
Acrobat SDK and JavaScript
578
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

correct answers 1 Correct answer

LEGEND , Mar 20, 2020 Mar 20, 2020

The custom calculate script for the field could be:

 

(function () {

    // Get the values from the input fields, as numbers
    var nDays1 = +getField("Days1").value;
    var nMIE1 = +getField("MIE1").value;

    // Calculate and set this field's value
    event.value = nDays1 == 1 ? 0.75 * nMIE1 : (nDays1 - 0.5) * nMIE1;

})();

 

That last line is equivalent to:

 

    if (nDays == 1) {
        event.value = 0.75 * nMIE1;
    } else {
        event.value = (nDays1 - 0.5) * nMIE1;
    }

 

Translate
LEGEND ,
Mar 20, 2020 Mar 20, 2020
LATEST

The custom calculate script for the field could be:

 

(function () {

    // Get the values from the input fields, as numbers
    var nDays1 = +getField("Days1").value;
    var nMIE1 = +getField("MIE1").value;

    // Calculate and set this field's value
    event.value = nDays1 == 1 ? 0.75 * nMIE1 : (nDays1 - 0.5) * nMIE1;

})();

 

That last line is equivalent to:

 

    if (nDays == 1) {
        event.value = 0.75 * nMIE1;
    } else {
        event.value = (nDays1 - 0.5) * nMIE1;
    }

 

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