Calculations adding digits instead of sum total
- February 18, 2020
- 3 replies
- 799 views
I have multiple, simple calculation scripts in my template that sum row fields horizontally and column fields vertically. The same fields are used to calculate both horizontal and vertical totals for the columns and rows. The problem I have is some of the totals add the fields as digits. For example 8+8+8 should equal 24 but in some totals 8+8+8 = 888. I have tried adjusting the calculation order but the problem seems to remain. If I physically enter a zero in the blank fields the calculation problem is fixed? I setting all the source fields default value to zero and hidden if zero, but if a row entry is missed the calculation reverts back to my poblem.
Is there a way to ignore blank values in the calculations for example below?
var prefix = "";
var nameParts = event.target.name.split(".");
if (nameParts.length > 2) {
prefix = nameParts[0] + "." + nameParts[1] + ".";
}
event.value = this.getField(prefix + "HoursRow1").value
+ this.getField(prefix + "HoursRow2").value
+ this.getField(prefix + "HoursRow3").value
+ this.getField(prefix + "HoursRow4").value
+ this.getField(prefix + "HoursRow5").value
+ this.getField(prefix + "HoursRow6").value
+ this.getField(prefix + "HoursRow7").value
+ this.getField(prefix + "HoursRow8").value
+ this.getField(prefix + "HoursRow9").value
+ this.getField(prefix + "HoursRow10").value;
if(event.value==0)
event.value="";
