Skip to main content
Known Participant
Apr 17, 2021 7:36 PM UTC
Answered

Round up or round down

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 is closed to new replies. Start a new post to keep the conversation going.
    try67
    try67Correct answer
    Community Expert
    Apr 18, 2021 5:39 PM UTC

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

    11 replies

    Legend
    Apr 18, 2021 4:55 PM UTC

    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. 

    Translate
    Known Participant
    Apr 18, 2021 4:02 PM UTC

     

     

    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

     

    Translate
    try67
    Community Expert
    Community Expert
    Apr 18, 2021 4:04 PM UTC

    You did not answer my question...

    Translate
    Known Participant
    Apr 18, 2021 4:10 PM UTC

    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.

    Translate
    try67
    Community Expert
    Community Expert
    Apr 18, 2021 8:50 AM UTC

    How are you currently calculating the value of this field?

    Translate
    Nancy OShea
    Community Expert
    Community Expert
    Apr 18, 2021 1:04 AM UTC

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

     

    Translate
    Nancy O'Shea— Product User & Community Expert
    John T Smith
    Community Expert
    Community Expert
    Apr 17, 2021 8:08 PM UTC