Rounds a floating-point number up or down to the nearest integer.
The Float.round function rounds a given
floating-point number to the nearest integer value and returns that
value.
If the decimal portion of a positive
floating-point number lies between .00000000 and .49999999, the number
is rounded down (toward zero, becoming less positive). Otherwise, a
positive floating-point number will be rounded up (away from zero,
becoming more positive).
If the decimal
portion of a negative floating-point number lies between .00000000 and
.49999999, the number is rounded up (toward zero, becoming less
negative). Otherwise, a negative floating-point number will be rounded
down (away from zero, becoming more negative).
If the number is already an integer, then that same integer value will
be returned.
If the browser does not support
floating-point arithmetic operations, then the browser will not
recognize the Float Library, nor any of the member functions. In
<?xml
version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD
WML 1.1//EN"
"http://www.WAPforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1">
<p>
round
example
</p>
<do type="accept">
<go
href="RoundExample.wmls#findround()" />
</do>
</card>
<card id="card2">
<p>
original number = $(number)
<br />
rounded
number = $(roundnumber)
</p>
</card>
</wml>
Code for RoundExample.wml
extern function findround()
{
var mydefault = "71.348";
var result = Dialogs.prompt("Enter any number",
mydefault);
var roundnum = Float.round(result);
WMLBrowser.setVar("number", result);
WMLBrowser.setVar("roundnumber",
roundnum);
WMLBrowser.go("RoundExample.wml#card2");
};
Code for RoundExample.wmls