Skip to main content
Known Participant
April 17, 2021
Answered

Round up or round down

  • April 17, 2021
  • 5 replies
  • 1217 views

I have a field "subtotal"

I want to round up or round down my value from "subtotal" field,

If 50.49 it will be 50.00

If 50.50 it will be 51.00

less than .50 will round down (.10-.49)

greater or equal to .50 will round up

please help me.

I am very new in JavaScript, but this is a great community to learn JavaScript.

 

    This topic has been closed for replies.
    Correct answer try67

    Using Product Option now.


    OK. Let's say the first quantity field is called Qty1 and the first unit price field is called UnitPrice1.

    As the custom calculation script of the first total price field enter the following:

     

    var qty = Number(this.getField("Qty1").valueAsString);

    var price = Number(this.getField("UnitPrice1").valueAsString);

    event.value = Math.round(qty*price);

    5 replies

    Legend
    April 18, 2021

    Be very careful. Money is much harder to work with than many people think, and accountants and others check for errors. Consider: 3 lines, each 4 @ $1.10. So each line is 4.40. You round each line to $4.  The bill must be for $12. 


    Seems simple? Now take the grand total. It's 4.40 x 3, which is 13.20 so you round it to $13. So you send someone a bill for which adds up to $12, but charge them $13.  This is likely to lead to bad discussions with accountants, tax authorities and others. 

    Known Participant
    April 18, 2021

     

     

    In 1st row total price will round up $21, and 2nd row total price will be $22.00

    19.49 will be 19.00, 19.50 will be 20

     

    try67
    Community Expert
    Community Expert
    April 18, 2021

    You did not answer my question...

    Known Participant
    April 18, 2021

    In 1st row total price will round up $21, and 2nd row total price will be $22.00

    19.49 will be 19.00, 19.50 will be 20

    How I will round up or round down Total Price value?

    I am new here.

    try67
    Community Expert
    Community Expert
    April 18, 2021

    How are you currently calculating the value of this field?

    Nancy OShea
    Community Expert
    Community Expert
    April 18, 2021

    [Moderator moved from Creative Cloud Services to Acrobat SDK.]

     

    Nancy O'Shea— Product User & Community Expert
    John T Smith
    Community Expert
    Community Expert
    April 17, 2021