2 Replies Latest reply on Oct 18, 2010 5:21 PM by heywang3

# round out division of two fields

I am currently using the Simplified form to do some divsion.  the equation  is - (fintotal/months)

I want to Round this field to 2 decimal points (100.23)

I am new to this and know very little.  I have seen the "Math.round" feature but can not figure out how to make it work with my need.

if this is my current "simplified code" (fintotal/months)  -  What is the custom script that will also round the feild??

THANKS!!

Chris

• ###### 1. Re: round out division of two fields

You can use the following as the custom Calculate script:

(function () {

// Get the field values as numbers
var v1 = +getField("fintotal").value;
var v2 = +getField("months").value;

// Perform the division and round to two decimal places

// if the denominator does not evaluate to zero

if (v2 !== 0) {
event.value = util.printf("%.2f", v1/v2);
} else {
event.value = "";
}

})();

This can be simplified to:

(function () {

var v1 = +getField("fintotal").value;
var v2 = +getField("months").value;

event.value = v2 ? util.printf("%.2f", v1/v2) : "";

})();

• ###### 2. Re: round out division of two fields

Thankyou so MUCH!!!!

spent 3 hours with no success!!!!!