Math problem with decimal places


#1

Hi all, I am having the darndest time trying to figure out a math formatting issue.
I have two global variables, in which I store the value of a repeater text object. I am trying to update the text of another widget with the values of my two global variables added together and set to two decimal places.
Here is the expression:
Flight total: €[[(leg1Total + leg2Total).toFixed(2)]]
This always equates to a NaN value

When I remove the ( ) around the two variables in the expression:
Flight total: €[[leg1Total + leg2Total.toFixed(2)]]
I get a number but it has two sets of decimal places and evaluates to “Flight total: €2,458.010.00”
Both variables are numbers with 2 decimal places and I end up with this wacky number that has two sets of decimal places.
What am I doing wrong here?


#2

Your first expression should work. What numbers are you using in your variables? I noticed that your example total includes a comma. If your variables have a comma, then they would return NaN.


#3

Yes, my numbers had commas in them. I guess I have to figure out a way to remove the commas, do the math, then put the commas back in. Thanks for your response! I just couldn’t figure it out. Now to figure out the comma problem.


#4

I figured out how to fix the comma problem, basically no commas in the repeater value, then add the comma back in using [[(leg1Total*1).toLocaleString()]]. Works like a charm. Thanks again for your help!


#5

You also can calculate after removed comma.
€[[(LVAR1.replace(“€”, “”).replace(",", “”)*1 + LVAR2.replace(“€”, “”).replace(",", “”)*1).toLocaleString]]