4. WMLScript Float Standard Library Quick Reference

WMLScript's Float standard library contains functions that help us perform a number of floating-point arithmetic operations.



WMLScript Quick Reference: Functions in the Float Standard Library

ceil(numeric_value)

Calculates the ceiling of numeric_value, i.e. it returns the smallest integer that is greater than numeric_value if numeric_value is a fraction, and returns numeric_value if numeric_value is an integer.

Example:

var w = Float.ceil(10.4);
var x = Float.ceil(10.5);
var y = Float.ceil(11);
var z = Float.ceil(-10.5);

w, x and y have the integral value 11.
z has the integral value -10.

floor(numeric_value)

Calculates the floor of numeric_value, i.e. it returns the largest integer that is smaller than numeric_value if numeric_value is a fraction, and returns numeric_value if numeric_value is an integer.

Example:

var w = Float.floor(11.4);
var x = Float.floor(11.5);
var y = Float.floor(11);
var z = Float.floor(-10.5);

w, x and y have the integral value 11.
z has the integral value -11.

int(numeric_value)

Truncates the fractional part of numeric_value.

Example:

var x = Float.int(5.5678);
var y = Float.int(-5.5678);

x has the integral value 5.
y has the integral value -5.

maxFloat()

Finds the maximum floating-point number supported, which should be 3.40282347E+38.

minFloat()

Finds the smallest positive nonzero floating-point number supported, which should be 1.17549435E-38.

pow(numeric_value1, numeric_value2)

Raises numeric_value1 to the power of numeric_value2, i.e. it calculates the result of numeric_value1numeric_value2.

Example:

var x = Float.pow(2, 3);
var y = Float.pow(10.5, 2.5);

x has the floating-point value 8.0.
y has the floating-point value 357.251.

round(numeric_value)

Returns the rounding of numeric_value.

Example:

var w = Float.round(10);
var x = Float.round(10.4);
var y = Float.round(10.5);
var z = Float.round(-10.5);

w has the integral value 10.
x has the integral value 10.
y has the integral value 11.
z has the integral value -10.

sqrt(numeric_value)

Calculates the square root of numeric_value.

Example:

var x = Float.sqrt(100);
var y = Float.sqrt(14);

x has the floating-point value 10.0.
y has the floating-point value 3.74166.



Previous Page Page 4 of 6 Next Page


Feedback Form (ExpandCollapse)

What do you think about this web page?






(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:

Please enter again to confirm:

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

A button for going back to the top of this page