rounding up with < .5 ?
Dar Scott
dsc at swcp.com
Thu Mar 14 17:55:01 EST 2002
On Thursday, March 14, 2002, at 02:58 PM, Yates, Glen wrote:
> If you always want to round up, why not just add 0.5 to the number
> you are
> rounding?
>
This is a good idea.
This will also round an positive integer to the next higher (more
positive) one. If this is not what Zac wants, he can test for an
integer and skip the round.
Is there a way to test that a number is an integer in Revolution?
Maybe one of these will work if a function is needed:
function isInt n
return n = trunc(n)
end isInt
or
function isInt n
return (n mod 1) = 0
end isInt
When writing functions "floor" or "ceiling" (the math names for
what we are talking about) or similar functions, you might want to
check that they do what you want for negative numbers.
The trunc() function might also be useful.
You will want to be careful in using round() if you care how your
function works for negative numbers. The dictionary entry says "If
the number is exactly between two [integer] numbers, round always
rounds the number up." If you interpret "up" as meaning "more
positive", this is not the case. If you interpret "up" as toward
the integer with the greater absolute value, then this is true. At
least, this is how it works on OS X, Revolution 1.1.1 B1. The
number -6.5 is rounded to -7.
Dar Scott
Some newbie guy
More information about the use-livecode
mailing list