Checking Whether
the Conversion of a String into a Floating-point Number is Possible:
isFloat() Function

The
isFloat() function is used to
check whether the conversion of a string into a floating-point number
is possible. The actual conversion should be done by the
parseFloat()
function, which will be
described in the next section.

The
syntax of isFloat() is shown
below:

Lang.isFloat(string);

isFloat()
returns true
if string can be
converted into the float type, otherwise it returns false.
If there are any errors or if the mobile device does not support
floating-point operations, the function returns invalid.
(Remember that the float()
function is used to check
whether a mobile device supports floating-point operations.)

The
following WMLScript example demonstrates how to use the isFloat()
function:

After
executing the above script, the variables w
to z contain the
Boolean value true.

If
non-numeric characters other than the above four (+ - . e) is present
in string, the WMLScript interpreter will
see if the characters before the non-numeric character form a valid
floating-point value. If yes, the isFloat()
function will still return true.
Here is an example:

x
= Lang.isFloat("100.999abc");y =
Lang.isFloat("100.999e-2abc");

After
executing the above script, both x
and y have the value
true.

Converting a String
to a Floating-point Number: parseFloat() Function

The
parseFloat() function is used
to convert a string to a floating-point number. Its syntax is:

Lang.parseFloat(string);

If
string cannot be converted to
the float type, the mobile device does not support floating-point
operations or an error occurs, parseFloat()
returns an invalid value. (Remember that the float()
function is used to check
whether a mobile device supports floating-point operations.)

The
following WMLScript examples demonstrate the behavior of the
parseFloat() function:

x
= Lang.parseFloat(100);y = Lang.parseFloat("100");

After
the execution of the script, both x
and y have the
floating-point value 100.0.

x
= Lang.parseFloat("100.999");y =
Lang.parseFloat("+100.999");

After
the execution of the script, both x
and y have the
floating-point value 100.999.

x
= Lang.parseFloat("-100.999");

After
the execution of the script, x
has the floating-point value -100.999.

x
= Lang.parseFloat("100.999e2");y =
Lang.parseFloat("100.999e-2");

After
the execution of the script, x
has the floating-point value 10099.9 and y
has the floating-point value 1.00999.

What do you think about this web page? It is very helpful. It is helpful, but some information I wanted is missing. It is not helpful. It has broken links. It has typos / grammatical mistakes. It has incorrect information. Others

(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Due to the amount of messages we received, we may not be able to reply to all messages.