spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column63


WMLScript Standard Libraries

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

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


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger


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

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