Back to Main Documentation Page
The JS Strict Data Types Integer method allows you to define a variable as an Integer data type and maintain the value as an integer.
To identify a variable as an Integer you would write the below code (where OptionalIntegerValue is some Integer value, if no value is inserted then 0 is returned).
MyVar1 = new Int(OptionalIntegerValue);
To set the value of the Integer to a new value you would use the below code (where IntegerValue is some Integer value).
MyVar1.Set(IntegerValue);
To return the data type of the Integer you would use the DataType property.
alert(MyVar1.DataType);
To get the value of an integer you would use the value property (the below would display the value).
alert(MyVar1.value);
To add an Integer value to the Integer you would use the add method as seen below (where IntegerValue is some Integer value).
MyVar1.add(IntegerValue);
To subtract an Integer value from the Integer you would use the sub method as seen below (where IntegerValue is some Integer value).
MyVar1.sub(IntegerValue);
To divide the Integer by an Integer value you would use the div method as seen below (where IntegerValue is some Integer value).
MyVar1.div(IntegerValue);
To multiply the Integer by an Integer value you would use the mult method as seen below (where IntegerValue is some Integer value).
MyVar1.mult(IntegerValue);
To compare if an Integer is equal to the Integer value you would use the CompareEq method as seen below (below is how you would use the CompareEq method in an if statement, where IntegerValue is some Integer value).
if(MyVar1.CompareEq(IntegerValue)){
alert("Statement is Equal");
{
To compare if an Integer is not equal to the Integer value you would use the CompareNotEq method as seen below (below is how you would use the CompareNotEq method in an if statement, where IntegerValue is some Integer value).
if(MyVar1.CompareNotEq(IntegerValue)){
alert("Statement is not Equal");
{
To compare if the Integer value is greater than an Integer value you would use the CompareGrt method as seen below (below is how you would use the CompareGrt method in an if statement, where IntegerValue is some Integer value).
if(MyVar1.CompareGrt(IntegerValue)){
alert("Statement Greater Than");
{
To compare if the Integer value is greater than or equal to an Integer value you would use the CompareGrtEq method as seen below (below is how you would use the CompareGrtEq method in an if statement, where IntegerValue is some Integer value).
if(MyVar1.CompareGrtEq(IntegerValue)){
alert("Statement Greater Than or Equal");
{
To compare if the Integer value is less than an Integer value you would use the CompareLess method as seen below (below is how you would use the CompareLess method in an if statement, where IntegerValue is some Integer value).
if(MyVar1.CompareLess(IntegerValue)){
alert("Statement Less Than");
{
To compare if the Integer value is less than or equal to an Integer value you would use the CompareLessEq method as seen below (below is how you would use the CompareLessEq method in an if statement, where IntegerValue is some Integer value).
if(MyVar1.CompareLessEq(IntegerValue)){
alert("Statement Less Than or Equal");
{
Below is an example of how you would use a function to maintain an Integer value.
function TestFunction(MyVar1){
//Set the Data Type of each Variable
MyVar1 = new Int(MyVar1);
alert("MyVar1 = " + MyVar.value);
}
Below is an example of how you would accomplish a for loop using the Integer method.
for(var a = new Int(0); a.value<20; a.add(1)){
alert("a = " + a.value);
}
Delicious
Digg
StumbleUpon
Propeller
Reddit
Magnoliacom
Newsvine
Furl
Facebook
Google
Yahoo
Technorati
Icerocket
Recent comments
12 hours 16 min ago
1 day 12 hours ago
2 days 5 hours ago
2 days 9 hours ago
2 days 20 hours ago
2 days 22 hours ago
6 days 12 hours ago
1 week 2 days ago
1 week 2 days ago
2 weeks 9 hours ago