FUNCTION:  Lang.parseInt

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 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"?>

<card id="card1">
   parseInt example
   <do type="accept">
      <go href="ParseIntExample.wmls#findparseint()" />

<card id="card2">
   integer number = $(intnumber)


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.setVar("intnumber", test);

Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information