"Truncate" formula Excel in JavaScript

I'm translating a formula Excel in Java script and I'm way out of my depth... If someone could help?

It's the formula in Excel: = TRUNC ((*(A2/100) B2) / 365,2)

In my Adobe Pro Document B2 is a field called 'RAD' and A2 is a field called ' MPIR '.»


I want to translate the formula truncated to JavaScript so that my calculation of field 'DAP_ONLY' in Adobe Pro rounds not upward (as seems to be the default setting)

For the moment, I have simplified notation field according to the value (RAD *(MPIR/100)) / 365 for my domain "DAP_ONLY" and the number format, 2 decimal places. That works if I want the result to round but in I need in fact the result is truncated instead.


I read material on the math.trunc in JavaScript function but do not know how to apply it because I don't speak JavaScript...  Is this something you can help with that?

Thank you!

Math.floor method is not equivalent to the TRUNC function. It's for positive values, but for negative values, you must use Math.ceil. Here's what might look like the script:

Custom calculation script

(function () {}

Get the values of the field as numbers

var RAD = + getField("RAD").value;

var MPIR = + getField("MPIR").value;

Perform the calculation

var result = RAD * MPIR / 100 / 365;

Truncate the result to two decimal places

If (result > = 0) {}

Event.Value = Math.floor(result * 100) / 100;

} else {}

Event.Value = Math.ceil(result * 100) / 100;

}

})();

Tags: Acrobat

Similar Questions

  • I need a conversion formula excel in javascript for a form to fill out.

    Here's the scenario,

    If a person moves for 1 or 2 days pay us a mealsrate of 75% per day. If 3 days or more we pay # days 2 days * 25%. I hope that makes sense.

    Days, F14 = Mealsrate = v7

    Formula in Excel

    = IF ($V$ 7 = 1, $F$14 *,($V$7*$F$14)-(($F$14*0.25) 0.75 * 2)) and it works.

    I am VERY NEW to javascript (like yesterday) in order not to laugh. I have really no idea what I'm doing, but I tried. Here's what I got. (by the way, it does not work)

    If (this.getField (("Days").) Value == '1')) {}

    var f = this.getField ("Mealsrate");

    F.value = Event.Value *. 75;

    } else event.value = (days * f.value)-(f.value *.25) * 2;

    I appreciate all the help I can get.

    Tracie

    I'll be back Monday, I hope I can find my post.

    OK, this Excel formula can reduce a little. The scipt to calculate custom next going to do with the formula:

    // Custom Calculate script
    (function () {
    
        // Get the inputs
        var days = getField("Days").value;
        var rate = getField("Mealsrate").value;
    
        // Set this field value
        if (days == 1) {
            event.value = 0.75 * rate;
        } else {
            event.value = (days - 0.5) * rate;
        }
    }
    

    It would be good idea to add additional code to deal with negative numbers in the two fields.

    Edit: fixed a fault

  • Conversion of a type formula Excel based in JavaScript

    I have an auto fill table in an Acrobat document. understood most of the equations simple but I have a slightly more complicated that requires JavaScript and I know that nada.

    The player entered two values (a), (b).

    and if I were writing the fomula in Excel, I would write:

    = a-(IF (b < 20,5 20,5, b)) + 41.5

    Any thoughts on how to translate this?  Thank you!

    If you want it to be a custom calculation for a field script, it could be:

    Custom text field calculation script

    (function () {}

    Get the field values as numbers

    var a = + getField("A").value;

    var b = + getField("B").value;

    Set the value of this field

    Event.Value = a - (b).< 20.5="" b="" :="" 20.5)="" +="">

    })();

    but replace 'A' and 'B' in the statements of getField with the names of actual field that you are using.

  • How to know which formula excel could not be converted to numbers?

    Hey guys,.

    3.6.2 numbers I used to open an EXCEL spreadsheet that uses a few different formulas.

    When you open the xlsx file, it tells me that failure to support formulas were replaced last calculated values.

    I have totally accept that, but is it possible to know, formulas THAT had to be replaced?

    Best regards

    Often, you will see a blue triangle in the upper left corner of the cells that have formulas not supported.  When you click the blue triangle, you should see a message like this:

    SG

  • If you use CFHEADER and CFCONTENT to disseminate an Excel file, Javascript still works?

    Hello, all,.

    I use a hidden iFrame which loads a page using CFHEADER and CFCONTENT to disseminate an Excel of a form submission.  I'm _trying_ to use JavaScript to change the value of the button element that sends the form to the parent page.

    I see no success.  JavaScript still works when a page using CFHEADER and CFCONTENT?

    I can't even a simple JS alert() to work.

    V/r,

    ^_^

    I don't expect Javascript to run when you use,

    These tags Coldfusion binary content, i.e. sending code Excel, result to the browser.

  • Formula Excel in the Script?

    = + F2 * 1.1 * G2

    Column (F2) is called Gross (header)

    1.1 is the multiplier of the brute

    G2 is where the customer fills the %

    He is so gross multiplied by 1.1 times the %

    ALL NEW here

    in your result field properties, you must first set to read-only.  Then go to the tab to calculate.  In the first box, you can create simple calculation of formulas by selecting the fields you want to be multiplied toghether.  To do this, you will need to create a field multiplier of 1.1% to the static address if you want to be able to select in the list.

    In the case that you do not want the multiply to show on your form, you can use the second box where you enter the calculation in simple notation.  Please note that the name of your fields have no '. ' to do.  The simple rating would be a little like excel: field * field * 1.1

    The last resort is the third area where you are free to use the code you like to more complicated calculations.  I think that your OK with either of the other two options.

  • Formula 'IF' Excel converted to Javascript

    Dear Forum

    I need to convert an editable PDF form Excel form.

    How this Excel formula converts in JavaScript:

    = IF (OR (D44 > F34;)) E44 > F12); "This text is displayed. « "; » »)

    Best regards, Mikko

    Assuming you want it's a custom calculation script, you can use the following text:

    Custom calculation script

    (function () {}

    Get the field values as numbers

    var D44 = + getField("D44").value;

    var F34 = + getField("F34").value;

    var E44 = + getField("E44").value;

    var F12 = + getField("F12").value;

    Set the value of this field

    Event.Value = D44 > F34 | E44 > F12? "This text will appear:";"

    })();

    but use real field names in declarations of getField. This assumes that the fields of entries have a digital format.

  • How can I convert Excel formula to Javascript?

    I tried using online Excel formula Beautifier to convert an Excel formula in javascript for use in Adobe Acrobat Pro XI > forms > text field properties > custom calculation Script, but it didn't work.  (I first changed the number of Excel cells for the correct names of the form (Acrobat) in the following calculation fields)

    Formula Excel using domain names: 

    = IF (goals = 1, GA1, IF (goals = 2, (SUM(GA1,GB1)/2), IF (goals = 3 (SUM(GA1,GB1,GC1)/3), SO (Goals = 4, (SU-M(GA1,GB1,GC1,GD1)/4)))

    Calculation Javascript converted using more Web site: 

    (Goals = 1, GA1, IF (objectives == 2, ((GA1,GB1)/2), IF (objectives == 3, ((GA1,GB1,GC1)/3), IF (objectives == 4, ((GA1,G B1,GC1,GD1)/4)))))

    There is no error message, but no results on the ground. I'd like if someone could help me with this script.  Thank you!!!


    Windows 8.1, Acrobat Pro XI

    Regardless of this JavaScript, it is not complete. Something a bit more readable would be:

    Get the field values as numbers

    var goals = + getField("Goals").value;

    var GA1 = + getField("GA1").value;

    var GB1 = + getField("GB1").value;

    var = GC1 + getField("GC1").value;

    var GD1 = + getField("GD1").value;

    Set this field value

    switch (goals) {}

    case 1:

    Event.Value = GA1;

    break;

    case 2:

    Event.Value = (GA1 + GB1) / 2;

    break;

    case 3:

    Event.Value = (GA1 + GB1, GC1) / 3;

    break;

    case 4:

    Event.Value = (GA1, GB1, GC1 + GD1) / 4;

    break;

    by default:

    Event.Value = "";

    break;

    }

    This assumes you have fields with these names.

  • Links JavaScript to the attachment in PDF from Word (or another Solution / Workflow)

    Hi all,

    After that hours of searching for a possible solution without getting even an approach I'm a little frustrated, so thanks for any help

    (Sorry for any spelling, I'm German ^^)

    My goal:

    A large (about 180 pages) PDF with approximately 60 documents (pdf, word, excel) in this PDF.

    Now, I want to have links in the text of the main PDF file that connects these attachments.

    I did it with Adobe Acrobat, PDF with normal links and Word/Excel using JavaScript Code (exportDataObject).

    My problem:

    The main PDF isn't static for all time, it happens.

    How can I avoid manually creating all the links after export of the Word Document in PDF format.

    Additional information for solutions:

    Modification of the PDF in Acrobat is AFAIK is not an option, because the layout as a header or page numbers the will / can not be changed with that.

    Hyperlinks are possible to do in Word a PDF file will take them along.

    It would also be possible with links to attachments?

    I don't necessarily have to to a specific show if you have any other solutions or options.

    I am grateful for all the help.

    You cannot create objects in JavaScript-event link in an external application, they must be created manually in Acrobat.

  • Win 7 (Pro) - Dism/online/Cleanup-Image /RestoreHealth - 87 error - could not fix corupted file

    Hello

    I was working on a large Excel file with a formula and stop of Excel to the answer.

    I restart my PC and go to the response center > troubleshooting > Performance. En error message says that a system problem has prevented this process to continue.

    I run SFC scannow and Dism/online/Cleanup-Image /RestoreHealth, I got error 87, unable to repair the damaged file.

    Win 7 previously od blue screen Crash after that.

    Can I know how to fix this?

    Is that this problem causes big intensive formula Excel file 37 MB?

    Thank you

    If the log file is the only corrupted file, and then deleting it will stop the error SFC utility. This assumes that the reader does not contain bad sectors. If there are bad sectors then by reinstalling Windows could possibly put a file system more important on this bad sector or sectors. Worse still the reader could deteriorate over time, creating bigger problems. Run a test of the car is an important step.

    Click Start
    Type: CMD, according to the results, right-click CMD
    Click on "Run as Administrator"
    At the command prompt, type: chkdsk /f /r
    When you restart your system, your computer will be scanned for errors and will try to correct them.

    If the problem persists, start to the Windows 7 Desktop, insert your Windows 7 disc, when the installation menu appears, click the option to make a upgrade on the current installation. Your personal files and your settings will be kept.

  • Determine the file name lengths

    Is this possible in Windows 7 to determine the length of the file names in an old and its subfolders?

    I tried some freeware programs that are supposed to do, but with not much luck.

    Thank you

    Sounds like pretty simple job for someone who knows how to write scripts that run in Windows, in something like Visual Basic.  Until this person comes to help here, I will mention that a method I've found is to go to the desired folder, copy the filepaths of the elements there, paste into an Excel sheet and use formulas to deal with the results.

    More details: when opening the file (or do a search in this folder), click on organize, click Select all, press on and hold down the SHIFT key and right-click on any file name, click Copy as path, go to an Excel spreadsheet and paste it into cell A2 to display a column to fill with paths.  Because we want to count the characters in the names of files and no paths together, we have a few delicate manufacturing formula Excel.

    I did the labels column for cells A1 to E1: entirepath filename extension namelength pathlength.  B2 E2 to cells contain these formulas:

    B2

    = IF (ISERROR (FIND("\",A2)), A2, RIGHT (A2, LEN (A2) - FIND ("|", SUBSTITUTE (A2, "-","|", LEN (A2) - LEN (SUBSTITUTE(A2,"\",""))))))

    C2

    (= IF (ISERROR (FIND(".",B2)),"", RIGHT (B2, LEN (B2) - FIND ("|", SUBSTITUTE (B2, ".","|", LEN (B2) - LEN (SUBSTITUTE(B2,".",)))) "" ")))

    D2

    = LEN (A2)

    E2

    = LEN (B2)

    Note that the namelength will include characters from file extension, or at least it did for me: I always keep the setting to display the file extension in Windows.

    For all information from production lines according to the formulas, select cells B2 to E2, copy, select the cells on the lower lines of the C2 at the last line with a filepath showing and paste.

  • Could someone please translate this excel formula in javascript for form = SUM ((G7*13), H7), I can't seem to understand

    I have to calculate the fields for a total when it comes to a field once 13 more another field for total, big help is greatly appreciated!

    The option of simplified field notation could be:

    G7 * 13 + H7

    But replace "G7" and "H7" with real field names. If domain names including spaces or other punctuation signs, you will need to escape each character with one-character.

    Custom JavaScript could be:

    (function () {}

    Get the field values as numbers

    var G7 = + getField("G7").value;

    var H7 = + getField("H7").value;

    Perform the calculation and the value of this field

    Event.Value = G7 * 13 + H7;

    })();

    Again, use the names of real field instead of the "G7" and "H7" above.

  • Worksheet Excel with a formula that must be in PDF format, helping with Javascript commands.

    I have a field whose value of the gross amount of the losses.

    When a number is entered the amount of the service is calculated with the formula below.

    = IF (F21 < 1, MAX (P3:P20),MAX(Q3:Q4))

    He is referring to the table below...

    so if the gross amount of the loss is less than 500 and then the amount of the service's 148

    If it is less than 2500 is the amount of the service of 1 290

    and so on.

    0-500= IF(I21>0,148)= IF (F21 = 1, 90)
    500-2500= IF(I21>500.01,290)= IF (F21 = 2, 125)
    2500-5000= IF(I21>2500.01,420)
    5000-10000= IF(I21>5000.01,585)
    10000-20000

    = IF(I21>10000.01,790)

    20000-50000= IF(I21>20000.01,965)
    50000-100000= IF(I21>50000.01,1640)
    more than 100000= IF(I21>100000.01,I21*0.024)

    Can I create a script that does essentially the same thing?

    The line which reads:

    var nGrossLoss = this.getField("GrossLoss").value;) get the value of the gross loss

    must be:

    var nGrossLoss = this.getField("GrossLoss").value; get the value of the gross loss

  • Conversion of excel in the calculation script formula

    How to convert this excel formula in the calculation script in pdf format?

    = IF (K10 = "PRF1120", 13, IF (K10 = "PRF1020", 10, IF (K10 = "PRO1020", 8, IF (K10 = "PRF1140", 5, IF (K10 = "ACC 1020", 3, IF(K10="PRO1080",4,""))))))

    The custom calculation script should be something like:

    Get the value of an input field

    var sVal = getField("K10").valueAsString;

    Set the value of this field depnding on the value of the input field

    switch (sVal) {}

    case 'PRF1120 ':

    Event.Value = 13;

    break;

    case 'PRF1020 ':

    Event.Value = 10;

    break;

    Repeat for the other possibilities

    by default:

    Event.Value = "";  This field blank

    }

    More information about the JavaScript statement switch are available in any decent JavaScript reference. Replace "K10" in the first line above with the actual name of the input field.

  • How to convert an Excel formula to a custom form Adobe Acrobat 9 calculation Script?

    Hello

    I'm not familiar whether with Javascript and need help to convert the Excel formula below so that I can enter a custom in the form of Adobe's PDF calculation Script. Here's the formula:

    (= If (E15 < 25.01,9.95,IF(E15 < 50.01,11.95,IF(E15 < 75.01,13.95,IF(E15 < 100.01,16.95,IF(E15 < 150,01, 19.95, IF (E15 < 200.01,24.95,IF(E15 > 200.00, E15 * 0.125)))

    Where 'E15' will be the text field called "Subtotal" in my Adobe's PDF form.

    Thanks for any help you can provide!

    Fortunately, JavaScript has the "switch" statement, so nested If statements can be avoided.

    var E15 = this.getField("Subtotal").value;

    {Switch (true)}

    case (E15< 25.01)="">

    Event.Value = 9.95;

    break;

    case (E15< 50.01)="">

    Event.Value = 11.95;

    break;

    case (E15< 75.01)="">

    Event.Value = 13.95. 13

    break;

    case (E15< 100.01)="">

    Event.Value = 16.95;

    break;

    case (E15< 150.01)="">

    Event.Value = 19.95;

    break;

    case (E15< 200.01)="">

    Event.Value = 24.95;

    break;

    case (E15 > 200):

    E15 = Event.Value * 0.125;

    break;

    by default:

    Event.Value = "";

    break;

    } / / end of switch.

Maybe you are looking for