Hoppa till huvudinnehållet

Addition in expressions

Kommentarer

5 kommentarer

  • Zack Robison

    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
  • David Major

    Thanks Zack, I have tried converting it to a number first and it still concatenates. Using Studio Workflow.

    0
  • Zack Robison

    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
  • David Major

    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
  • Dan Joyce

    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

Du måste logga in om du vill lämna en kommentar.