[thelist] JavaScript : How to determine if float or integer

Rob Whitener rwhitener at DesignOptions.com
Tue Jan 28 09:45:34 CST 2003


I don't know if using (mynumb mod 1) will tell you if the number is an
integer.  There shouldn't ever be a remainder when something is divided by
1, so the modulus will always equal 0.  Try dividing something like .0256 by
1 and see if there is a remainder.

Rob

-----Original Message-----
From: Dawn Gabriel [mailto:dawn at ergito.com]
Sent: Tuesday, January 28, 2003 10:38 AM
To: thelist at lists.evolt.org
Subject: Re: [thelist] JavaScript : How to determine if float or integer


Slightly quicker way to do it:

function isInt(myNum) {
         // get the modulus: if it's 0, then it's an integer
         var myMod = myNum % 1;

         if (myMod == 0) {
                 return true;
         } else {
                 return false;
         }
}

At 07:00 PM 1/28/2003 +0500, you wrote:
>From: "Markus Staas"
>To: <thelist at lists.evolt.org>
>Sent: January 28, 2003, Tuesday 4:00 PM
>Subject: [thelist] JavaScript : How to determine if float or integer
>
>
> > Do you know any other way than scanning for the point in the whole
> > variable?
>
>Use indexOf() method.
>
>E.g.
>
><script language="JavaScript">
>
>var numbContainer
>var whatType
>var notNumber
>
>numbContainer=3.141                 // assigning a number to the variable
>
>notNumber="a"+numbContainer   // this step will convert the number
>                                                     // into string without
>effecting the original number
>
>whatType=notNumber.indexOf(".")
>
>alert(whatType)    // a posititive integer (2) is returned whcih tells the
>                             // position of point in the number
>
>numbContainer=786             // assigning another number to the variable
>
>notNumber="a"+numbContainer   // this step will convert the number
>                                                    // into string without
>effecting the original number
>
>whatType=notNumber.indexOf(".")
>
>alert(whatType)    // as point will not be found therefore -1 will be
returned
>
></script>
>
>Hope this helps!
>
>Syed Zeeshan Haider.
>http://syedzeeshanhaider.faithweb.com/
>
>--
>* * Please support the community that supports you.  * *
>http://evolt.org/help_support_evolt/
>
>For unsubscribe and other options, including the Tip Harvester
>and archives of thelist go to: http://lists.evolt.org
>Workers of the Web, evolt !

--
* * Please support the community that supports you.  * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester
and archives of thelist go to: http://lists.evolt.org
Workers of the Web, evolt !



More information about the thelist mailing list