Addition in expressions
Having trouble with the simplest of things....trying to take a number stored as a string attribute returned in a query (eg 302), and add 1 to it (303). I can subtract, divide, multiple, but can only concatenate 1. Seems like it should work using += but no luck. Can someone please help? What is the operator to add a number to a number?
Tried: =$query1.feature.attributes.IDParcel += 1
Also tried casting the attribute to a number, then += 1, and it still concatenates.
Thanks,
David
-
JS is figuring out what you want with those other operators, the issue is that "+" means "concatenate" when it comes to strings in ways that "/", "*", and"-" don't so that's what it's guessing you want when you add a number to a string. You need to convert the string to a number, try the parseInt() function or the Number() constructor.
=Number($query1.feature.attributes.IDParcel) + 1
1 -
Thanks Zack, I have tried converting it to a number first and it still concatenates. Using Studio Workflow.
0 -
If it concatenates, then it's probably not a number. I'd recommend breaking out your cast logic into its own activity and watch it using the debug console, make sure the result is of the correct type.
0 -
Thanks again. I got it working. Yes the trouble was it was not actually converting to a number. The value is stored with leading zeros in the attributes maybe that was the problem. Using the Cast activity to a number did not actually convert it, still had the leading 0. I had to multiply it by 1 then the result was a number and I could add 1 to that just using the +. Probably the wrong way to get there but it is working.
David
0 -
As per Zach’s earlier comment, I’ve used parseInt() function in the past and it is probably a bit cleaner than multiplying the value by 1.
0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
5 Kommentare