WMLScript » Lang » Lang.abs

Syntax:
Lang.abs(value)
value
The mandatory value parameter can be any positive or negative single-precision floating-point number or any positive or negative integer number (including zero). The floating-point number must reside on or between the largest number and the smallest nonzero number supported by the browser. These boundary values can be determined using the Float.maxFloat and Float.minFloat functions.

Returns the absolute value.

The Lang.abs function returns the absolute value of a specified number. If the number is a floating-point, then an absolute floating-point number is returned. If the number is an integer, then an absolute integer will be returned.

Several functions in the Float Library can also be used to manipulate numbers.

Examples

Code:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.WAPforum.org/DTD/wml_1.1.xml">
<wml>

<card id="card1">
   <p>
   abs example
   </p>
   <do type="accept">
      <go href="AbsExample.wmls#findabs()" />
   </do>
</card>

<card id="card2">
<p>
   original number = $(number)
   <br />
   absolute number = $(absnumber)
</p>
</card>

</wml>
Explanation:

Code for AbsExample.wml

Language(s): WML
Code:
extern function findabs()
{
   var mydefault = "-71.348";
   var result = Dialogs.prompt("Enter any number", mydefault);
   var absnum = Lang.abs(result);
   WMLBrowser.setVar("number", result);
   WMLBrowser.setVar("absnumber", absnum);
   WMLBrowser.go("AbsExample.wml#card2");
};
Explanation:

Code for AbsExample.wmls

Language(s): WML

See Also: