Formula "1" + "2" returns 3 and not 12

Formula "1" + "2" returns 3 and not 12.

And any other "number" + "number" formula returns a sum of this two numbers (so it treats "number" as a number and not as a string).

Not sure if it’s a bug, but looks like a bug to me. Is it?

this is not a bug a.f.a.i.k

the plus operator is primarily for arithmetical addition. so coda will try to convert the operands to numbers and perform addition on them.

however, if either operand cannot be converted to a number, coda will convert them both to text and perform a concatenation.

so text operands composed of plus/minus sign, digits, decimal point… will be converted to number first.

when you need to concatenate two or more text operands, you should use the Concatenate() function. it is best practice, clearer to the reader, and more reliable.


1 Like

Yeah, I figured out I can use Concatenate() in this case.

But what’s weird and made me think it’s a bug is that ToText(1) + ToText(2) returns 3 too.
I would definitely expect Coda NOT to convert a string back to a number in this case as I just told Coda to convert numbers to strings.

And I don’t understand why Coda would want to treat “1” as number 1.

well, to understand why it behaves like this, you need to accept that coda sees the plus operator as PRIMARILY for adding numbers.

so no matter what you tell it to do to the operands before the plus executes, it will ALWAYS check to see if it can do an arithmetic addition first.

so its the presence of the ‘+’ that is forcing this behaviour




This has caught me too. Apparently there is a demand from people that want to be able to convert text type to number when using “+”. Not sure that I agree, but…

Same :relaxed:

Took me some time to figure out this Coda behavior.
The thing that "1" + "Text" returns "1Text" made it more puzzling.

Also in my case it was "0" + "another number" and I thought maybe Coda treats "0" as blank/null value.