WMLScript Float
Standard Library
WMLScript's
Float standard library contains a number of functions for performing
floating-point arithmetic operations. Note that the Float standard
library is only available on mobile devices that support
floating-point arithmetic operations. To check whether a mobile
device supports floating-point operations, use the float()
function of the Lang standard library. If a mobile device does
not support the Float standard library, a call to any of its
functions will return invalid.
In
the following sections, we will look at some of the more commonly
used functions in the Float standard library.
Rounding a Numeric
Value: round() Function
The
round() function of the Float standard library returns the rounding of a numeric value. If
any error occurs, it returns invalid.
The following WMLScript example demonstrates its use:
w
= Float.round(10.4); x = Float.round(10.5); y =
Float.round(-10.5); z = Float.round(10);
After
the execution of the above script, w
has the integral value 10, x has the integral value 11,
y has the integral value -10 and z has the integral
value 10.
Truncating the
Fractional Part of a Numeric Value: int() Function
The
int() function of the Float standard library is used to truncate the fractional part of a
numeric value. If any error occurs, it returns invalid.
The following WMLScript example demonstrates the use of the int()
function:
w
= Float.int(10.4); x = Float.int(10.5); y = Float.int(-10.5); z
= Float.int(10);
After
the execution of the above script, w
and x contain
the integral value 10, y
contains the integral value -10 and z
contains the integral value 10.
|
Feedback Form (ExpandCollapse)
|
|