# If statement with arithmatic

I'm using Libre Calc but for some reason the following always produces the string TRUE

=IF(K3="",D3,D3*K3)


What I want is if Cell K3 is empty, then print the value of Cell D3, otherwise print the value of D3 multiplied with K3.

What am I doing wrong?

edit retag close merge delete

Sort by » oldest newest most voted

Formula looks correct. If cell is formatted as Boolean Value formula will return "TRUE", formatting cell as number should fix the issue.

more

What is called "the string TRUE" by the OP is not a string (text) but the way Calc displays a numerical value in a cell set to the number format 'BOOLEAN' (listed as 'Boolean value'). It may be heavily misleading but is a fact that Calc displays TRUE for any value not equal to 0 an FALSE for the value 0 only in this case. [Let K3 be 0 to experience this.]

The second misleading behaviour of Calc in this context is that it automatically applies the number format BOOLEAN to a cell if it has the number format 'General' in advance and is recalculated to the result of a BOOLEAN function.

The third craziness I see in the fact that a cell once formatted this way will display every numeric result as 'BOOLEAN' even if the formula was edited to something without any relation to logic, "=PI()/8", eg.

And the fourth incredibility (or was it the zeroth) is that an IF function is classified logical if the third or both the second and the third parameters are missing. It will produce the logical result of the condition as its own result for the missing parameter. Very bad.

@johnlai2004 , for some reason, most likely because of a typo, had first entered an incomplete IF expression. Then he rectified that. This did not heal the consequences of silly smart automatisms.

You see?

@Edward is right in principle. We get rid of the insistent wrong format by choosing another numeric format but 'BOOLEAN'. 'BOOLEAN', however, is also a number format. I cannot but accept that.

By the way: Entering a numeric constant into the cell will also switch off the BOOLENA hysteria.

more