Skip navigation
MJBateman1
Currently Being Moderated

Calculations with Rounded Numbers

May 29, 2012 12:12 PM

I've created a form in Adobe X that has a few calculated fields.  For ease of conversation, we'll call them Field A, Field B and Field C (see below).  I need Fields A and B to be rounded to the nearest whole number so that Field C is also a whole number.  I've tried formatting Fields A and B to show no decimals but the calculaton is still being performed on the non-rounded numbers.  Can anyone help with this?  Thanks.

 

Field A - Field B = Field C

 
Replies
  • George Johnson
    11,671 posts
    Aug 11, 2002
    Currently Being Moderated
    May 29, 2012 12:44 PM   in reply to MJBateman1

    You'll have to use JavaScript. The code for the custom calculation script for your example would be:

     

    // Cust calculation script

    (function () {

     

        // Get the field values, rounded to nearest integer

        var v1 = Math.round(+getField("fieldA").value);

        var v2 = Math.round(+getField("fieldB").value);

     

        // Set this field value to the difference

        event.value = v1 - v2;

     

    })();

     

     

    Replace "fieldA" and "fieldB" in the code above with the actual field names.

     
    |
    Mark as:
  • Currently Being Moderated
    May 29, 2012 12:52 PM   in reply to MJBateman1

    Well this is the way JavaScirpt works and for many calculations the unrounded nubmers are needed for the calculaitons.

     

    You need to set the value of the calculated field to the rounded value.

     

    I would use a custom calculation script and you can use JavaScript's "Math.round" method or Acrobat's "util.printf" method.

     

    event.value = Math.round(event.value);

     

    event.value - util.printf("%,1 .0f", event.value);

     
    |
    Mark as:
  • George Johnson
    11,671 posts
    Aug 11, 2002
    Currently Being Moderated
    May 29, 2012 1:37 PM   in reply to MJBateman1

    It's not math.round, it's Math.round.

     
    |
    Mark as:
  • Currently Being Moderated
    May 29, 2012 2:17 PM   in reply to MJBateman1

    Yes you can, and I would do it for each calculated field where you want the rounded value of the calculation used.

     

    If you use the Math object's round method you use:

     

    Math.round(FloatingPointValue)

     

    "Math" has to have the first letter capitalized.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points