December 6, 201015 yr I think this may be a quick one. I want a function that returns a Boolean result if a number is divisible by 4 ie it returns a whole number when divided by 4. Is this possible. Many thanks
December 6, 201015 yr The following function will return 1 if a number is evenly divisible by 4. It will return 0 otherwise. If the number is zero it will return 0. This is an arbitrary choice, but since you asked for a whole number instead of an integer, that indicated to me that you needed a zero result when given zero as input. Case( theNumber = 0; 0; /* Make this result 1 if your logic Mod(theNumber; 4) = 0; 1; 0 )
December 6, 201015 yr This: returns a Boolean result if a number is divisible by 4 is NOT the same as: it returns a whole number when divided by 4. A Boolean result is either True (1) or False (0). To get a Boolean result if a number is divisible by 4, you can use = not Mod ( number ; 4 ) To return a whole number when divided by 4 ... well it depends on whether you want to round, or discard the remainder, or whatever. The simplest way is: Div ( number ; 4 ) which performs an integer division (i.e. any remainder is discarded).
December 6, 201015 yr The difference being... ? I may be misremembering my elementary school math terminology. I thought a whole number was a "counting number", i.e. positive integers. Integers of course can be zero and negative.
December 6, 201015 yr My dictionary defines "integer" as "a whole number". But it is true that the term does not have a precise definition and some use it to mean "a natural number".
December 6, 201015 yr Author Hi sorry did not intend to create a debate. I should have been clearer. Basically what I was looking for is if a number in this case a year was divisible by four (and would therefore denote a leap year) it would trigger conditional formating on the field I have for 29th Feb. The not Mod ( number ; 4 ) worked like a dream Thank you all for your help.
December 6, 201015 yr a year was divisible by four (and would therefore denote a leap year) That's not a good test - it will fail in 2100. Try = not Mod ( Year ; 4 ) and Mod ( Year ; 100 ) or not Mod ( Year ; 400 ) or = Month ( Date ( 2 ; 29 ; Year ) ) = 2
December 6, 201015 yr ... or: DayOfYear( Date( 12 ; 31 ; Year ) ) = 366 ... but this is kind-of the same as Month ( Date ( 2 ; 29 ; Year ) ) = 2
December 26, 201015 yr Author If they are still using this databased in 2100 I will be impressed, although probably dead haha. Thanks for the tip though will change my code.
Create an account or sign in to comment