Using two hyphens in front of an Excel function.

  • Thread starter Thread starter dlamarche
  • Start date Start date
D

dlamarche

Yesterday I saw an Excel function that had two hyphens "--" before the
function name. I do remember reading about this a few months ago but I do not
remember the use. I was NOT double negation as I remember well. There was
another obscur use. Anybody has an idea?

Thanks
 
The double negation (changes the sign from positive to negative and
then negative to positive) is one way to convert the TRUE or FALSE
result of a comparison operation to the numeric equivalent (TRUE = 1,
FALSE = 0). Basically, it multiplies the TRUE or FALSE by -1 twice,
which forces Excel to change the value to a number.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
dlamarche said:
Yesterday I saw an Excel function that had two hyphens "--" before the
function name. I do remember reading about this a few months ago but
I do not remember the use. I was NOT double negation as I remember
well. There was another obscur use. Anybody has an idea?

Yes, it __is__ simply double negation.

Sometimes it is used to convert "numeric text" or Boolean values (TRUE,
FALSE) to bona fide numbers. But any arithmetic operation will do the
trick. Double negation per se is not always necessary.

For example, consider =TEXT(A1,"hh:mm"), which might be used to round a time
value in A1 to the precision of a minute. The TEXT function itself returns
a string. If you want a time value (a number), you can use double negation,
to wit: =--TEXT(A1,"hh:mm").

But suppose you want to add 1 minute to the rounded time value. It would be
sufficient to do: =TEXT(A1,"hh:mm")+TIME(0,1,0).

PS: Even where double negation is useful, there are alternatives.
=1*TEXT(A1,"hh:mm") is equivalent to =--TEXT(A1,"hh:mm").
 
Thanks you very much for the info gentlemen. I was very intriged but now it
is clearer. So -- was a double negation after all. Thanks Chip, I visit your
site regularly and recommended it to many of my students!
 
Back
Top