两个减号的含义(“双一元”) [英] Meaning of two minus signs together ("double unary")
问题描述
例如:
此公式获取字符串日期并将其转换为Excel日期序列号:
= - (MID(S2,4 ,3)& LEFT(S2,3)&MID(S2,7,4))
公式工作正常,我只想了解公式中的 -
。
@ JNevill的评论对我来说似乎是一个很好的答案,但为了答案考虑在A1和 Y $中
Y
c $ c>在B1。这个公式:
=(A1 = B1)
返回TRUE。如前所述,将操作符放在前面( 0 +
或 1 *
),并将布尔值变为 1
或 0
如果B1(仅)更改为,例如 X
。
单数减去否定。 0 -
或 -1 *
,在前面返回 -1
A1和B1等于 Y
。 和 -1
结果变为 1
,与 = - 1 *(A1 = B1)
。
但是乘以1(或添加零)是无意义的,可能只是去:
= - (A1 = B1)
请注意,因为评估发生的顺序,上述方法与以下不同:
= - A1 = B1
没有意义,所以返回 #VALUE!
。 / p>
您的示例中的文本函数( MID
和 LEFT
返回字符串,因此,使用这样的函数(单独)构建今天的日期索引(在1900日期系统中为42311)返回Excel不能识别为可能表示日期的五个字符。转换为数字格式并表示为日期,这应该是今天。
所以格式化为单元格作为文本并输入42311,然后重新格式化为日期,结果仍然是$ code> 42311 。将单元格格式化为常规,然后输入:
= - (42&311)
然后格式化为日期,您应该看到一些看起来像今天的东西。
What does the two -
sign mean at the beginning of a formula?
Ex: This formula gets a string date and converts it into an Excel date serial number:
=--(MID(S2,4,3)&LEFT(S2,3)&MID(S2,7,4))
The formula works fine, I just want to understand the --
in the formula.
@JNevill's Comment seems a good answer to me but for the sake of an Answer consider Y
in A1 and Y
in B1. This formula:
=(A1=B1)
returns TRUE. As mentioned, stick an operator in front (with 0+
, or 1*
) and the Boolean is turned into 1
, or 0
if B1 (only) is changed to, say, X
.
The single minus negates that. 0-
, or -1*
, at the front returns -1
for both A1 and B1 equal to Y
. Negate that and the -1
result becomes 1
, say with =--1*(A1=B1)
.
But then multiplying by one (or adding zero) is pointless, might as well just go for:
=--(A1=B1)
Note that because of the order in which the evaluations take place, the above is not the same as:
=--A1=B1
which has no meaning so returns #VALUE!
.
Text functions (MID
and LEFT
in your example) return strings, so constructing a date index for today for example (42311 in the 1900 date system) with such functions (alone) returns five characters Excel does not recognise as possibly representing a date. Converted to numeric format and represented as a date this should look like 'today'.
So format as cell as Text and enter 42311, then reformat as Date and the result is still 42311
. Format a cell as General and enter:
=--("42"&"311")
before then formatting as Date and you should see something that looks like 'today'.
这篇关于两个减号的含义(“双一元”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!