Local variables not summing up numerical values properly


#1

test_sumList.rp (84.2 KB)

Issue

  • When entering numbers in the text fields (positive, neg, decimal), the total number doesn’t sum properly
  • Sum seems to be adding in additional numbers
    Sample file of what am trying to accomplish uploaded for reference

Goal

  • Enter values in the “Count” column
  • Values should be numerical only, can be positive or negative and may include up to one decimal
  • “0” in the Overall total count column should adjust as numbers are entered in any text field in the sum column
  • At time of submit, final value in the overall sum column should then populate on the start page + sum page


#2

I’ve run into similar issues where the decimals get off for whatever reason. You can force the result down to 1 decimal (or any other number of decimals) using .toFixed by doing something like this:

[[(LVar1 + LVar2 + LVar3 + LVar4 + LVar5 + LVar6 + LVar7 + LVar8 + LVar9).toFixed(1)]]


#3

This is a problem with JavaScript, not specifically Axure:

One way around this is to used toFixed() to truncate the value, or instead don’t use decimals at all, but store your values as integers and then convert them to decimals when you display them. For example, instead of storing a price in dollars as 1.41, store it in cents as 141 and then divide it by 100 when you want to display it.


unlisted #4