Ceiling and Floor in Lingo

February 3rd, 2009

People occasionally have questions when trying to find a ceiling or floor function in the Lingo library so I figured I’d post it here for future googlers.

Lingo didn’t include these two math functions, but you can write your own functions and keep them in your personal library of goodies.

on floor aFloat
 return integer(aFloat) - (aFloat < integer(aFloat))
end

on ceil aFloat
 return integer(aFloat) + (aFloat > integer(aFloat))
end

If you are working with Javascript these functions are built in:

Math.ceil(aFloat);
Math.floor(aFloat);

Entry Filed under: Basic Lingo,Javascript,Math

2 Comments Add your own

  • 1. Rob Gordon  |  February 4th, 2009 at 12:22 pm

    Good one Raman! For a slight speed boost though, you can store the integer so it’s not being calculated twice. E.g.:

    on floor aFloat
    i = integer(aFloat)
    return i – (aFloat < i)
    end

  • 2. Nonoche  |  February 26th, 2009 at 6:09 am

    there’s also the flash way:

    on floor afloat
    mathobj = new object("math")
    return mathobj.floor(afloat)
    end

    on ceiling afloat
    mathobj = new object("math")
    return mathobj.ceil(afloat)
    end

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Director Sites

Calendar

February 2009
M T W T F S S
« Jan   Mar »
 1
2345678
9101112131415
16171819202122
232425262728  

Archives

Recent Posts

Recent Comments