Fix/Int (Floor) function oddity in ColdFusion 8

I've discovered an odd little "bug" in the Fix and Int functions in ColdFusion 8. The Fix/Int functions work similarly to the Floor function in other languages:

According to the ColdFusion 8 LiveDocs

Int - Calculates the closest integer that is smaller than number. For example, it returns 3 for Int(3.3) and for Int(3.7); it returns -4 for Int(-3.3) and for Int(-3.7)

Fix - Converts a real number to an integer. If number is greater than or equal to 0, the closest integer less than or equal to number. If number is less than 0, the closest integer greater than or equal to number.

Now, if you do #Fix(15)# or #Int(15)# the functions return the correct value of 15. However if you do #Fix((6.84/45.60) * 100)# or #Int((6.84/45.60) * 100)# the functions return 14 which is incorrect since the equation equates to 15.

Bug or Feature?

Related Posts

This entry was posted in ColdFusion, Programming and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
  • http://jean.posterous.com Jean Vincent

    There could be a rounding error and your equation might actually return “15 – epsilon”. To find out try to print (6.84/45.60) * 100 – 15. If this returns something like 1.333e-15 there is a floating point rounding error (http://en.wikipedia.org/wiki/Round-off_error).

  • Anonymous

    Hi Jean, thanks for this. I believe that this is the exact issue. ColdFusion runs on top of Java in which I can replicate the issue. This doesn’t happen in PHP using the floor function.