两个减号在一起的含义(“双一元") [英] Meaning of two minus signs together ("double unary")
问题描述
公式开头的两个 -
符号是什么意思?
What does the two -
sign mean at the beginning of a formula?
例如:此公式获取字符串日期并将其转换为 Excel 日期序列号:
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 的评论对我来说似乎是一个很好的答案,但为了得到答案,请考虑 A1 和 Y<中的
Y
/code> 在 B1 中.这个公式:
@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)
返回 TRUE.如前所述,在前面贴上一个运算符(带有0+
,或1*
),布尔值就变成了1
,或0
如果 B1(仅)更改为 X
.
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
.
单个减号否定了这一点.0-
,或-1*
,在前面返回-1
对于A1和B1都等于Y
.否定 that 并且 -1
结果变成 1
,用 =--1*(A1=B1)
说.
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
没有意义所以返回#VALUE!
.
文本函数(在您的示例中为 MID
和 LEFT
)返回字符串,因此例如使用此类函数构建今天的日期索引(1900 年日期系统中的 42311)(单独)返回五个 Excel 无法识别为可能代表日期的字符.转换为数字格式并表示为日期,这应该看起来像今天".
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'.
因此将单元格格式化为Text并输入42311,然后重新格式化为Date,结果仍然是42311
.将单元格格式化为常规并输入:
So format a 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屋!