Microsoft KB Archive/57313

Word: Comparing Decimal Numbers in Print Merge IF Statement

PSS ID Number: Q57313 Article last modified on 03-07-1997

=
========================================================= 3.00 3.01 3.02 4.00 MACINTOSH kbprint

= SUMMARY =

When comparing numbers in the Print Merge IF function, if the value of the field and the value of the condition don’t match in type (for example, both text or both integer) you will receive the error “Not a valid integer to compare to.”

The IF comparison only supports comparison of integers or text. Decimals are treated as text. Since decimal values are treated as text, the numbers must be encased in quotation marks. However, this causes the numbers to be compared as a text string.

For example,

<>

will be found as true because 1 is less than 2.

= MORE INFORMATION =

The following information outlines a method to convert the decimal values to integers. This method requires the modification of the data document, as well as changing each number individually in your comparison fields in your main document. It is suggested that the numbers created be placed into a new field, rather than replacing the existing numbers, and this new field then be used for the comparison.


 * 1) Multiply both numbers to be compared by a number that makes them integers. For example, multiply each number by 10 raised to the maximum number of characters found after the decimal in either of the values to be compared. If you are comparing 2.23 and 1.234, you would multiply by 1000 because the second value has three numbers after the decimal.
 * 2) If the resulting numbers do not have the same number of characters, add leading zeros to the shorter of the two.
 * 3) Now compare the resulting values.

The following is a specific example:

As shown above, <> is found as true because 1 is less than 2.

To work around this, multiply both by 100, as show below:

100.37 X 100 = 10037 2.23 X 100 = 223

Add leading zeros to 223 so that it has the same number of characters as 10037. The values you are left with are as follows:

10037 00223

Now the statement <> is found as FALSE because 1 is not less than 0 (zero).

KBCategory: kbprint KBSubCategory: kbfield kbmerge Additional reference words: macword macword5 ====================================================================== ============================================================================= Copyright Microsoft Corporation 1997.