# 18. 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.

## 18.1. 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.

## 18.2. 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.

Previous Page | Page 52 of 71 | Next Page |

**Click Here for Full Table of Contents**)

- 1. WMLScript Introduction
- 2. Hello World WMLScript Example
- 3. Compiling WMLScript Code
- 4. WMLScript Language Rules
- 5. Defining WMLScript Functions
- 6. Calling WMLScript Functions
- 7. WMLScript Variables
- 8. WMLScript Data Types
- 9. WMLScript Variables Vs WML Variables
- 10. Passing Arguments to Functions By Value and By Reference
- 11. WMLScript Operators
- 12. WMLScript Conditional Statements
- 13. WMLScript Looping Statements
- 14. WMLScript Standard Libraries Overview
- 15. WMLScript WMLBrowser Standard Library
- 16. WMLScript Dialogs Standard Library
- 17. WMLScript String Standard Library
- 18. WMLScript Float Standard Library
- 19. WMLScript Lang Standard Library
- 20. WMLScript URL Standard Library
- 21. WMLScript Example: Validating Form Data