Announcement

Collapse
No announcement yet.

Calculating percentage

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calculating percentage

    Ho do I create a box that when I add a number, it subtracts that percentage from the cell above it? I want to subtract 15% from the cell amount of currency above it.
    i.e. 15% of $258.00

  • #2
    Place this as a calulation script in the target field, you must adapt the above field's name:

    var nVal = Number(this.getField("cell_above").value) * 0.15;
    event.target.value = Number(this.getField("cell_above").value) - nVal;

    Comment


    • #3
      Thank you JRB. The script works but as a newbie I would like to work it this way. I have 3 boxes stacked. The top one is 'subtotal', the next one down I want to type in the percentage of discount which for now is 15%, and the bottom box is the 'Total,', which then shows the total with the 15 % discount. The script you gave me works fine but it doesn't connect the the middle discount box where I would want to type in the amount of discount, which for now is 15%. For now, the 'Discount box ' is dead so I just put any number in there which is fine because your script works for the total box but it be great if I can type in a number the discount box and it automatically calculates it for the total box. Hope this makes sense. Thanks

      Comment


      • #4
        JACKIEJAY
        I will submit your request to our engineer team and create a new JS for you, will back to you soon!

        Comment


        • #5
          Here is it:

          var nDiscount = this.getField("discount").value;
          var nPrice = this.getField("cell_above").value;

          var nVal = Number(nPrice) * Number(nDiscount);
          event.target.value = Number(nPrice) - nVal;

          Comment


          • #6
            Thanks so much for your effort. Not quite sure what part of scripts go into which boxes calculations fields. The Subtotal Box, Discount amount box, and the Total amount box. Plus the appropriate edits of your script to make it work.

            Click image for larger version

Name:	Screenshot 2021-02-23 113911.jpg
Views:	19
Size:	19.3 KB
ID:	181711

            Comment


            • #7
              The script above cannot work, I made a mistake.
              Use this one as a Calculation script in the "TOTAL" field. Since I don't know what is the Format used by this field, I assume that the value returned by the DISCOUNT field is 15, or 15%


              var nDiscount = this.getField("DISCOUNT").value;
              var nPrice = this.getField("SUBTOTAL").valueAsString.replace(/\%/gim,"");
              // remove the % car. if exist

              if (nPrice.length > 1) {var nZero = "";}
              else {var nZero = "0";}
              var nPrice = "0." + nZero + nPrice;
              // add a zero and a dot before the percent value

              var nVal = Number(nPrice) * Number(nDiscount);
              event.target.value = Number(nPrice) - nVal;




              It would be easier if you could share an example or a mockup in PDF.
              Last edited by JRB; 02-24-2021, 05:54 PM.

              Comment


              • #8
                JRB
                THANKS... I attached a mockup as suggested. This particular client is for 15% discount but I want to be able to adjust that for other clients in the future. For now 15% is what I need. Also, I think I have an older version that does not have the option to add it so I can't put in a date selector on the left column, Can that be something added?

                Thanks!
                Attached Files

                Comment

                Working...
                X