You need to round a number to an integer value.

ColdFusion comes with a number of built in functions to work with rounding whole numbers (integers):

The round() function rounds a number to the closest integer. For example:

test1: <cfoutput>#round(99.5)#</cfoutput>
<br>
test2: <cfoutput>#round(-99.5)#</cfoutput>
test1: 100 
test2: -100

The fix() function's output depends on if the number you pass in to it is positive or negative. If the number you pass in is greater then or equal to 0, the function returns the closets integer less then the number passed in. If the number you pass in is less then 0, the function returns the closest integer greater then the number in question:

test1: <cfoutput>#fix(99.5)#</cfoutput>
<br>
test2: <cfoutput>#fix(-99.5)#</cfoutput>
test1: 99 
test2: -99

The int() function returns the closest integer that is smaller than the number you pass in:

test1: <cfoutput>#int(99.5)#</cfoutput>
<br>
test2: <cfoutput>#int(-99.5)#</cfoutput>
test1: 99 
test2: -100

The ceiling() returns the closest integer greater than the number you pass in:

test1: <cfoutput>#ceiling(99.5)#</cfoutput>
<br>
test2: <cfoutput>#ceiling(-99.5)#</cfoutput>
test1: 100 
test2: -99

This question was written by Jeremy Petersen
It was last updated on January 10, 2006.

Categories

Numbers

Comments

comments powered by Disqus