WMLScript Standard Libraries: The Lang Library - Part I | WebReference

WMLScript Standard Libraries: The Lang Library - Part I


WMLScript Standard Libraries

The Lang Library - Part I

The Lang library contains a set of functions that are the basis of the WMLScript language core. This library mimics a lion share of the functionality provided by JavaScript.

abs()

This function returns the absolute value of a given number. If the given number is of type integer, the function returns an integer. If the given number is of type floating-point, the function returns a floating point value.

Syntaxabs(value)
Parametersvalue = Number
ReturnsNumber or invalid
Examples:var a = -6;
var b = Lang.abs(a); // b = 6;
var c = -8.4;
var d = Lang.abs(c); // d = 8.4

min()

This function returns the minimum value of the given two numbers. WMLScript date type conversion rules for integers and floating point numbers are used for comparison. The value and type of the smaller number are selected. If values are identical, the first value is returned.

Syntaxmin(value1, value2)
Parametersvalue1 = Number
value2 = Number
ReturnsNumber or invalid
Examples:var a = Lang.min(40, 50.3); // a = 40 (integer)
var b = Lang.min(40, 35.7); // b = 35.7 (floating)

max()

This function returns the maximum value of the given two numbers. WMLScript date type conversion rules for integers and floating point numbers are used for comparison. The value and type of the larger number are selected. If values are identical, the first value is returned.

Syntaxmax(value1, value2)
Parametersvalue1 = Number
value2 = Number
ReturnsNumber or invalid
Example:var a = Lang.max(40, 50.3); // a = 50.3 (floating)
var b = Lang.max(40, 35.7); // b = 40 (integer)

parseInt()

This function returns an integer value defined by the sting parameter. Parsing ends on the first encountered character that is not a leading "+", "-", or a decimal digit. In case of a parsing error, an invalid value is returned.

SyntaxparseInt(value)
Parametersvalue = String
ReturnsInteger or invalid
Examples:var a = Lang.parseInt("9351"); // a = 9351
var b = Lang.parseInt(" 936 x/y"); // b = invalid

parseFloat()

This function returns a floating-point value defined by the sting parameter. Parsing ends on the first encountered character that cannot be parsed as part of a floating-point number. In case of a parsing error, an invalid value is returned.

SyntaxparseFloat(value)
Parametersvalue = String
ReturnsFloating-point number or invalid
Examples:var a = Lang.parseFloat("935.14"); // a = 935.14
var b = Lang.parseFloat(" -85.17e2 Kg"); // b = -85.17e2
var c = Lang.parseFloat("4.2e"); // b = invalid

isInt()

This function returns true if its parameter can be converted into an integer by parseInt(). Otherwise, false is returned.

SyntaxisInt(value)
Parametersvalue = Any
ReturnsBoolean or invalid
Examples:var a = Lang.isInt("-935"); // a = true
var b = Lang.isInt(" -85.17"); // b = true
var c = Lang.isInt("foobar"); // b = false
var d = Lang.isInt("@157"); // d = false
var e = Lang.isInt(invalid); // e = invalid

isFloat()

This function returns true if its parameter can be converted into a floating-point number by parseFloat(). Otherwise, false is returned.

SyntaxisFloat(value)
Parametersvalue = Any
ReturnsBoolean or invalid
Examples:var a = Lang.isFloat("-935"); // a = true
var b = Lang.isFloat(" -85.17e3"); // b = true
var c = Lang.isFloat("foobar"); // b = false
var d = Lang.isFloat("@157"); // d = false
var e = Lang.isFloat(invalid); // e = invalid

Next: How to use the Lang library - Part II

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

Created: June 5, 2000
Revised: June 5, 2000

URL: http://www.webreference.com/js/column63/2.html