Quick References
ADO
ASP
CSS2
HTML
JavaScript
Jet SQL
VBScript
WML
WMLScript
WSH
XHTML
XML DOM
XSLT
Features
Knowledge Base
Tutorials
Partners
ZVON.ORG
XML
Planet Source Code
VisualBuilder
Web Design
Your HTML Source
XML/XSLT Forums
ASPAlliance
Scripts
Programmers Heaven
Tek-Tips Forums
Developer Fusion
Code Project
Lang.parseFloat
Lang.float
Lang.isFloat
Lang.isInt
Float.int
FUNCTION: Lang.parseInt
Lang.parseInt
(value)
The
Lang.parseInt
function converts the given string value into an integer number.
The function parses the string value until the end is reached or the first invalid character is encountered. Parsing does not continue past a decimal point or an e exponential designator. If the very first character is not a digit, a plus + sign, or a negative - sign,
invalid
is returned. Also, if an error occurs,
invalid
is returned.
You can also use the
Lang.isInt
function to test a string to pre-determine if it can be converted into an integer number. This can prevent
invalid
from being returned.
The
Float.int
function will return the integer portion of a floating-point number.
The mandatory
value
parameter can be any string that begins with numeric characters or begins with a plus or minus sign followed by numeric characters.
Here are the results of some conversions:
Value
Return
"101"
101
"-101"
-101
"984.653"
984
"42 feet"
42
"7 inches by 8 inches"
7
"75e3"
75
"83.67e-9"
83
"$12.99"
invalid
"The size is 4x8 feet"
invalid
In this example, if the string can be converted to an integer, the converted number is returned. If the string cannot be converted,
false
is returned.
Code for ParseIntExample.wml
<?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>
parseInt example
</p>
<do type="accept">
<go href="ParseIntExample.wmls#findparseint()" />
</do>
</card>
<card id="card2">
<p>
integer number = $(intnumber)
</p>
</card>
</wml>
Code for ParseIntExample.wmls
extern function findparseint()
{
var result = Dialogs.prompt("Enter number", "");
var test = Lang.isInt(result);
if(test == true)
{
var intnum =
Lang.parseInt(result)
;
WMLBrowser.setVar("intnumber", intnum);
WMLBrowser.go("ParseIntExample.wml#card2");
}
else
{
WMLBrowser.setVar("intnumber", test);
WMLBrowser.go("ParseIntExample.wml#card2");
}
};
Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information