IF THEN ... LESS THAN Negative number doesn't return true value

J

Jonathan Crow

I am putting and IF ... THEN field into a merge document
where the code is

{IF {MERGEFIELD "MyMergeField" } <"-5" "I am true" "I am
false"}

If the MyMergeField = -30 I get the result I am true.
If the MyMergeField = 0 I get the result I am false.
If the MyMergeField = 5 I get the result I am false.
So far so good.

If the MyMergeField = -3 I get the result I am true.

Since I am testing to see whether the value is less than -
5 the result should be I am false.

Anyone have any ideas why this is happening and how I can
fix it?

Thanks,
Jonathan
 
G

Greg

Jonathan,

Try putting your Mergefield in a formula field:

{If { = { Mergefield "MyMergeField" } } < -5 "I am
true" "I am false"
 
G

Greg Maxey

Jonathan,

Either way is working for me. What is set a your negative number marker in
Control Panel>Regional and Language Settings>Customize??
 
J

Jonathan Crow

Greg,
I checked the regional settings and it shows that the
Regional Options for Numbers for Negative Sign Symbol is -
, the negative number format is -1.1

The wierd thing about this is that the test is for number
less than -5, for all values except for single digit
negative values it behaves as it should. The only values
for which it isn't working are -9 through -1.

So, for -10 the result is true (as it should be)
For -9 the result is false (wrong)
same for -8, -7, -6, and -5.
For -4 the result is true (wrong)
same with -3, -2, -1.

When I get to 0 the result is false (as it should be).

So, why it is only not working on single digit negative
numbers is beyond me.

Thanks,
Jonathan
 
G

Greg Maxey

Jonathan,

Hmm.... puzzling indeed. An you are not the only one. I bookmarked a
number "test" and stuck it in the field { If test < "-5" "True" "False" }
and I am seeing the same odd behavior you describe with single digit
negatives. Don't know an answer, but still looking.
 
D

Doug Robbins - Word MVP

Hi Greg/Jonathon,

It appears that Word is only doing a Text comparison, not a numeric one. As
there is no way of forcing Word to convert the items being compared to
numbers or to make the comparison on a numeric basis, your only hope will
be, if you have the data in something like Access or Excel, to do the
comparison there and have a field that displays the result of the
comparison, rather than have Word do the comparison.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
C

Cindy Meister -WordMVP-

Hi Jonathan,

As Doug says, for Word, everything is text. It also doesn't
help with numeric comparisons if you put something ins
"quotes"! You'll generally have better luck leaving the
quotes away if you want to do "number stuff". In this case,
however, that doesn't help. BUT...

I am putting and IF ... THEN field into a merge document
where the code is

{IF {MERGEFIELD "MyMergeField" } <"-5" "I am true" "I am
false"}

If the MyMergeField = -30 I get the result I am true.
If the MyMergeField = 0 I get the result I am false.
If the MyMergeField = 5 I get the result I am false.
So far so good.

If the MyMergeField = -3 I get the result I am true.

Since I am testing to see whether the value is less than -
5 the result should be I am false.

Anyone have any ideas why this is happening and how I can
fix it?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan
24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 
G

Greg Maxey

Cindy,

Thank you, thank you, thank you. I have been frustrated over this one.
Particularily the lack of documentation official or unofficial.
 
P

Peter Jamieson

If you want to do

IF { a } < { b }

you can also consider

{ IF { ={ a }-{ b } } < 0 "True" False" }

(AFAIK it only works because all numbers less than 0 start with a "-", which
is lower in the collation sequence). Probably not much use if you also need
to detect small rounding errors.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top