[thelist] JavaScript : How to determine if float or integer
Syed Zeeshan Haider
szh at softhome.net
Tue Jan 28 08:01:01 CST 2003
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/
More information about the thelist
mailing list