Skip to main content
New Participant
November 17, 2016
Answered

Rounding up dollars to nearest whole dollar (script)

  • November 17, 2016
  • 1 reply
  • 1200 views

Hello - I have very little experience with java and Adobe and am just now learning in order to make fillable forms. I need to create a calculation for dollar amount rounded to the nearest whole dollar.

So I have a text field (linefive) that is multiplied by .005 to create (linesix). Obviously linesix could be only change ($.07) or more than that ($2.34). Is there a way that this calculation can can round up to the nearest whole dollar amount for the output? (e.g. .47 = $1 (because it can't be zero) or $2.55 = $3)

Please help me, I really appreciate it. Thank you so much!!!

This topic has been closed for replies.
Correct answer George_Johnson

You'll have to use a custom calculation script. It could be:

// Custom calculation script

(function () {

    // Get the input field value, as a number

    var v1 = +getField("linefive").value;

    // Calculate the value

    var val = 0.005 * v1;

    // Round up to nearest dollar and set this field value

    event.value = Math.ceil(val);

})();

Change "linefive" to whatever the actual field name is if needed.

1 reply

George_JohnsonCorrect answer
Inspiring
November 17, 2016

You'll have to use a custom calculation script. It could be:

// Custom calculation script

(function () {

    // Get the input field value, as a number

    var v1 = +getField("linefive").value;

    // Calculate the value

    var val = 0.005 * v1;

    // Round up to nearest dollar and set this field value

    event.value = Math.ceil(val);

})();

Change "linefive" to whatever the actual field name is if needed.

New Participant
November 17, 2016

THANK YOU SO MUCH!!! That worked perfectly.

You are the best!