Is the number 0 true?

Hi,

I had written some formulas that assumed that a numeric field with the value 0 (zero) would evaluate to false, like in other languages I use. For example, the formula

If(0, true, false)

would return false. I believe this had been working in Coda like this. Today I noticed that my formulas were behaving oddly, and I realized it’s because 0 evaluates as true, as demonstrated here:

Was there a change to Coda’s handling of 0 or am I misremembering things?

I’ve started doing explicit comparisons, like If([Input number] != 0, true, false), but I’m curious.

Thanks,
Wallace

Dear @Wallace_White,

Good question and a common challenge, as you will always have to compare same value types.

First in the condition section you do not set a condition:

What should the input number be?
image

Either both are text and you compare them:

Or you compare in both columns number values:

Hey @Wallace_White ,

why don’t you use checkboxes for booleans? In formulas the column value would already be a condition, like if(input number true, …, …).
The checkbox column formula would just be
Input number != 0

Best regards
Marius

1 Like

@Wallace_White you are getting unexpected behavior because Coda is answering a different question than you. You are asking is 0 true? but when you put a singular value into an if statement, Coda evaluates is value blank?

This feels more useful, after using Coda for several years, the ability to see if a value exists and to act accordingly … and I understand that other languages have their preferences. Good luck!

2 Likes

Thanks, everyone. My question wasn’t about text or boolean inputs—I appreciate that those have their considerations—but rather a numeric input.

I’ll conclude that I wasn’t following good practice for Coda to assume that 0 would evaluate equivalently to false, so I will do explicit comparisons, such as If([Input number] != 0, "Input was non-zero", "Input was zero").

That’s easy enough to do and a good habit anyway. And if I want to evaluate whether a numeric input is blank, I’ll continue to explicitly check by using IsBlank().

Thanks again,
Wallace

1 Like