Testing for odd/even number
ArborX


Summary
Script example testing if the last page in the document is odd or even.

It can also be necessary to check whether or not a number is odd or even. Because numeric variables are always whole numbers, dividing the number you want to test by two, and then multiplying it by two, will produce different results according to whether the number was odd or even. In the example below we find out if the last page of a document is even or odd:

 getvar 01535 "lastpage" 3
 ^tmp=^lastpage 5
 ^tmp/2 7
 ^tmp*2 9
 ^tmp-^lastpage 11
 ?=^tmp boxit \^lastpage is even^ 13
 ?-^tmp boxit \^lastpage is odd^ 15

Document created on 08-Feb-2003 (revision 1)