Another question is, do you need the calculated value to be rounded. Note that the rounded display value may not be the same as the actual field value or the computed value. This difference could cause additional issues if the computed value is used in another calculation.
Since your field appear to have a row or column index, will these calculations be performed more than once with different field values.
Your first equation:
// row / column index
var nIndex = 1;
// field names
var DIName = "DistanceInches" + nIndex;
var TSName = "TimeSeconds" + nIndex;
var TMName = "TimeMinutes" + nIndex;
// get field values as numbers
var DistanceInches = Number(this.getField(DIName).value);
var TimeSeconds = Number(this.getField(TSName).value);
var TimeMinutes = Number(this.getField(TMName).value);
event.value = ""; // default value for no calculation;
if(TimeSeconds != 0 || TimeMinutes != 0) {
event.value = DistanceInches / (TimeSeconds / 60 + TimeMinutes);
// some debugging information for example
console.show();
console.clear();
console.println("Distance inches: " + DistanceInches);
console.println("Time seconds: " + TimeSeconds);
console.println("Time minutes: " + TimeMinutes);
console.println("Result unrounded: " + event.value);
console.println("Result rounded: " + util.printf("%,0 0.2f", event.value));
}
Try different values and observe the results in the JavaScript console to see that the displayed value is not the exact value of the computation or field.