Jed69 Posted December 6, 2010 Posted December 6, 2010 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
TheTominator Posted December 6, 2010 Posted December 6, 2010 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 )
comment Posted December 6, 2010 Posted December 6, 2010 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).
comment Posted December 6, 2010 Posted December 6, 2010 you asked for a whole number instead of an integer The difference being... ?
TheTominator Posted December 6, 2010 Posted December 6, 2010 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.
comment Posted December 6, 2010 Posted December 6, 2010 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".
Jed69 Posted December 6, 2010 Author Posted December 6, 2010 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.
comment Posted December 6, 2010 Posted December 6, 2010 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
Vaughan Posted December 6, 2010 Posted December 6, 2010 ... or: DayOfYear( Date( 12 ; 31 ; Year ) ) = 366 ... but this is kind-of the same as Month ( Date ( 2 ; 29 ; Year ) ) = 2
Jed69 Posted December 26, 2010 Author Posted December 26, 2010 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.
Recommended Posts
This topic is 5139 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now