View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > Int PreviousNext

Int

Calculates the closest integer that is smaller than number.

An integer, as a string.

Mathematical functions

Int(number)

Ceiling, Fix, Round

Parameter

Description

number

Real number to round down to an integer

<h3>Int Example</h3>
<p>Int returns the closest integer smaller than a number.

<p>Int(11.7) : <cfoutput>#Int(11.7)#</cfoutput>
<p>Int(-11.7) : <cfoutput>#Int(-11.7)#</cfoutput>
<p>Int(0) : <cfoutput>#Int(0)#</cfoutput>

Contents > CFML Reference > ColdFusion Functions > Int PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


DracTK said on Aug 13, 2003 at 8:35 AM :
This function description is misleading, it doesn't convert ALL numbers to the first smallest int. It only converts numbers when the function argument is within the range of allowed integers. For example try this int(GetTickCount()). Int should convert very large number that getTickCount() produces to integer, but it does not. I suggest that either the description of this function be changed or this function's behavior be modified to fit its description.
No screen name said on Oct 2, 2003 at 1:12 PM :
This function is more accurately the Floor() function rather than the Int() function. So, for example, Int(2.5) = 2.0 and not 2. This is an important distinction if you want to use this number to index an array or query as an attempt to do so throws an exception.
PsG-1b said on Dec 15, 2003 at 4:08 PM :
Responding to DracTK,

I tried int(gettickcount()) and as far as I can tell it's working properly. The number returned by gettickcount() is an integer already, "integer" meaning mathematical integer. As far as the integer data type, that is only 4 bytes, or 32 bits, and we all know the biggest signed number that can be represented in 4 bytes is 2^32-1, or 4294967295. gettickcount() returned something two orders of magnitude higher than this number. And the int() function still works as intended because it turns that large number into a data-type akin to floating point. So it's still a mathematical integer, but just represented differently. (100 is an integer, and I would *think* that 1e2, 1.0e2, and 1.000000e2 are all integers as well since they mean the same thing)
Adam Cameron said on Apr 1, 2004 at 4:50 PM :
Note: this function's handling of negative numbers is incorrect. It should return the integer portion of the number (simply casting it as either an INT or a LONG as appropriate), and that is all.
The integer portion of -3.7 is -3, not -4.
halL said on Apr 2, 2004 at 7:21 AM :
As indicated in the Oct 2, 2003 comment, this function is really a floor function.
It returns the largest integer that is smaller than the parameter.
Therefore it returns 3 for 3.3 or 3.7 and -4 for -3.3 and -3.7
Future versions of this page will state this clearly.
halL said on Apr 2, 2004 at 7:36 AM :
I should also have noted with respect to numbers that are too large to be represented internally as numeric integers, In ColdFusion MX 6.1, the Int function returns a value, but it can be invalid. For example the following code has numbers consisting of 13 digit 9s, which ColdFusion can represent internally as a string or convert to a real number, but cannot represent internally as a numeric integer:

<cfoutput>
9999999999999: #int(9999999999999)#<br>
-9999999999999: #int(-9999999999999)#<br>
</cfoutput>

This code displays:
9999999999999: 1E+013
-9999999999999: -1E+013
Which means that ColdFusion actually rounded up by one!
This behavior is consistent with ColdFusion 5.0 behavior.
s_bywater said on Jun 30, 2005 at 2:11 PM :
This is pedantic, but it should be "Calculates the closest integer that is smaller than or equal to number." Int(3) = 3, not 2. :)

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/funct121.htm