JS Strict Data Types - Float

Tagged:  

Back to Main Documentation Page
The JS Strict Data Types Float method allows you to define a variable as a Float data type and maintain the value as a Float.

To identify a variable as a Float you would write the below code (where OptionalFloatValue is some Float value, if no value is inserted then 0 is returned).

MyVar1 = new Float(OptionalFloatValue);

To set the value of the Float to a new value you would use the below code (where FloatValue is some Float value).

MyVar1.Set(FloatValue);

To return the data type of the Float you would use the DataType property.

alert(MyVar1.DataType);

To get the value of a Float you would use the value property (the below would display the value).

alert(MyVar1.value);

To add a Float value to the Float you would use the add method as seen below (where FloatValue is some Float value).

MyVar1.add(FloatValue);

To subtract a Float value from the Float you would use the sub method as seen below (where FloatValue is some Float value).

MyVar1.sub(FloatValue);

To divide the Float by a Float value you would use the div method as seen below (where FloatValue is some Float value).

MyVar1.div(FloatValue);

To multiply the Float by a Float value you would use the mult method as seen below (where FloatValue is some Float value).

MyVar1.mult(FloatValue);

To compare if a Float is equal to the Float value you would use the CompareEq method as seen below (below is how you would use the CompareEq method in an if statement, where FloatValue is some Float value).

if(MyVar1.CompareEq(FloatValue)){
    alert("Statement is Equal");
{

To compare if a Float is not equal to the Float value you would use the CompareNotEq method as seen below (below is how you would use the CompareNotEq method in an if statement, where FloatValue is some Float value).

if(MyVar1.CompareNotEq(FloatValue)){
    alert("Statement is not Equal");
{

To compare if the Float value is greater than a Float value you would use the CompareGrt method as seen below (below is how you would use the CompareGrt method in an if statement, where FloatValue is some Float value).

if(MyVar1.CompareGrt(FloatValue)){
    alert("Statement Greater Than");
{

To compare if the Float value is greater than or equal to a Float value you would use the CompareGrtEq method as seen below (below is how you would use the CompareGrtEq method in an if statement, where FloatValue is some Float value).

if(MyVar1.CompareGrtEq(FloatValue)){
    alert("Statement Greater Than or Equal");
{

To compare if the Float value is less than a Float value you would use the CompareLess method as seen below (below is how you would use the CompareLess method in an if statement, where FloatValue is some Float value).

if(MyVar1.CompareLess(FloatValue)){
    alert("Statement Less Than");
{

To compare if the Float value is less than or equal to a Float value you would use the CompareLessEq method as seen below (below is how you would use the CompareLessEq method in an if statement, where FloatValue is some Float value).

if(MyVar1.CompareLessEq(FloatValue)){
    alert("Statement Less Than or Equal");
{

Below is an example of how you would use a function to maintain a Float value.

function TestFunction(MyVar1){
    //Set the Data Type of each Variable
    MyVar1 = new Float(MyVar1);
    alert("MyVar1 = " + MyVar.value);
}

Below is an example of how you would accomplish a for loop using the Float method.

for(var a = new Float(0); a.value<20; a.add(1)){
    alert("a = " + a.value);
}