5 Replies Latest reply on Jun 13, 2006 6:04 AM by Newsgroup_User

# Simple rounding trick needed

I guess this is an easy question for the advanced lingo scripter: I'm using the following script to determine the price the user has to pay. The thing is that I want to round the value (GBcounter/4) upward. ie. Such that 5/4 becomes 2 :-)

Hope anyone can help me!

Mich
• ###### 1. Re: Simple rounding trick needed
Could be a better way than this, but you could define your own function.
Something like this. Basically performs the division and adds 1 if there is
any remainder.

on roundUpDivision numerator, denominator
result = numerator / denominator
if numerator mod denominator <> 0 then result = result + 1
return result
end

• ###### 2. Re: Simple rounding trick needed
FYI, you can also use the ceil method of the Flash Math class:

p = newObject("math")
put p.ceil(5/4.0)

-- 2.0000

--
Dave -
www.blurredistinction.com

• ###### 3. Re: Simple rounding trick needed
Works like a charm! But I have no idea how it does the trick. I can't find this type of code in my Director 8 dymistified book :-) Do you know where I can find more on this topic?

Thanks a lot!

Mich
• ###### 4. Re: Simple rounding trick needed
>>Do you know where I can find more on this topic?

I'm not 100% sure what your question is, sorry. If you mean more on the
Flash math object, you can find that in the Flash help docs. Creating Flash
objects, is covered in some detail in the Director docs, but there aren't
specific bits of code - as again, those would be in the Flash help. If you

--
Dave -
www.blurredistinction.com

• ###### 5. Re: Simple rounding trick needed
Circusmich wrote:
> Works like a charm! But I have no idea how it does the trick. I can't
> find this type of code in my Director 8 dymistified book :-) Do you
> know where I can find more on this topic?
>
> Thanks a lot!
>
> Mich
>
> p = newObject("math")
> put p.ceil(5/4.0)

It might be faster to use pure Lingo:

on ceiling(x)
chopped=bitOr(x, 0)
if x=chopped then
return chopped
end if
if x>0 then
return chopped+1
else
return chopped-1
end if
end

If you need stuff about maths, then try http://mathworld.wolfram.com/ or
http://mathforum.org/.

Andrew