Ensure a variable is divisible by 4

Will McGugan will at willNOmcguganSPAM.com
Mon Dec 4 12:32:26 EST 2006


geskerrett at hotmail.com wrote:
> I am sure this is a basic math issue, but is there a better way to
> ensure an int variable is divisible by 4 than by doing the following;
> 
> x = 111
> x = (x /4) * 4
> 
> Just seems a bit clunky to me.
> 

Depends what you mean by 'make it divisable'. Do you want to check it is 
divisible or do you want to make it divisible? And if you want to make 
it divisible do you want to go to the next multiple of 4, or the previous?


Will McGugan
--
http://www.willmcgugan.com



More information about the Python-list mailing list