An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

Ceiling, Fix, Int, Round

October 25, 2004 ·

ColdFusion has four functions that take a floating point number and return an integer. Although the documentation is pretty clear about what each function does, you might not realize just how subtle the differences are between the functions. Here's sample output from a small test program that demonstrates how the four functions behave for a variety of positive and negative numbers:
ceiling(-4.9) is -4, fix(-4.9) is -4, int(-4.9) is -5, round(-4.9) is -5
ceiling(-4.4) is -4, fix(-4.4) is -4, int(-4.4) is -5, round(-4.4) is -4
ceiling(4.9) is 5, fix(4.9) is 4, int(4.9) is 4, round(4.9) is 5
ceiling(4.4) is 5, fix(4.4) is 4, int(4.4) is 4, round(4.4) is 4
Some of you will recognize the behavior of int() as being what some languages provide as floor().

Tags: coldfusion

3 responses

  • 1 Bill Rawlinson // Oct 25, 2004 at 5:56 PM

    to be honest I've never understood why it isn't called floor. Even in math classes at University we had ceiling and floor; not just in comp sci. Calling it floor would be more clear, I think. Of course, at this point in the CF lifeline it is a bit late to go changing somethings name that has been around for, just about, forever.
  • 2 joe rinehart // Oct 25, 2004 at 7:01 PM

    i think this is the most in one day i've ever seen rounding functions discussed - cftalk, coldfusion-howto, here, and I had a VB person asking me how to get fix() in C# earlier.

    thanks for the post sean - i'm sure i would've forgotten the subtleties, but i'm sure to remember now.


  • 3 Doug // Oct 26, 2004 at 7:08 AM

    CF isn't the only lang to use Int() for Floor()

    Now, if we can just get the standard boolean ops in... ;)