[Javascript] Is integer?
Hassan Schroeder
hassan at webtuitive.com
Mon May 29 08:59:46 CDT 2006
Peter Lauri wrote:
> Is there any function that checks if something is an integer? I did not find
> one and created this temporary function:
>
> function isInteger(thenumber) {
> thenumberceil = Math.ceil(thenumber);
> if(thenumberceil>thenumber) return false;
> else return true;
> }
perhaps more simply: return (Math.round(x) == x)? true : false ;
> Why I actually need this is because I need to find out if a year is a "skott
> year" (do not know the English word, but the years when February has 29 days
> instead of 28). Is there any function for that?
In English, "leap year", but no, I'm not aware of a Date function
to check that.
> function isSkottYear(y) {
> yeardiv = y/4;
> if(isInteger(yeardiv)) return true;
> else return false;
> }
alternatively: return ((y % 4) == 0 )? true : false;
Or, using dates directly:
var D1 = new Date(y, 1, 29);
var D2 = new Date(y, 2, 1);
return (D1.getTime() == D2.getTime())? false : true;
There's always more than one way to do it :-)
HTH!
--
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design === (+1) 408-938-0567 === http://webtuitive.com
opinion: webtuitive.blogspot.com
dream. code.
More information about the Javascript
mailing list