Skip to main content
Participant
March 20, 2020
Resuelto

Excel to JavaScript

  • March 20, 2020
  • 1 respuesta
  • 620 visualizaciones

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

Este tema ha sido cerrado para respuestas.
Mejor respuesta de George_Johnson

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;
    }

 

1 respuesta

Inspiring
March 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;
    }