<cfset myList = "32,48,64,72,144,160,200,288,320,400,512,576,640,720,800">
<cfoutput>#getNextLowest(myList, 12)#</cfoutput>
<cffunction name="getNextLowest" returntype="numeric">
<cfargument name="list" type="string" required="true" />
<cfargument name="value" type="numeric" required="true" />
<cfset local = structNew() />
<cfset local.return = 32 />
<cfloop index="local.index" list="#arguments.list#">
<cfif local.index lt arguments.value and local.index gt
local.return>
<cfset local.return = local.index />
</cfif>
</cfloop>
<cfreturn local.return />
</cffunction>
Regards
Dale Fraser
http://learncf.com
-----Original Message-----
From: Andy Matthews [mailto:[EMAIL PROTECTED]
Sent: Wednesday, 3 October 2007 3:20 PM
To: CF-Talk
Subject: Next lowest number from array (or list).
Say that I have a list of allowed nmbers:
32,48,64,72,144,160,200,288,320,400,512,576,640,720,800
If I give the user the option of selecting a number, and it happens to not
be in this list, how might I go about automagically selecting the next
lowest number? One exception being if the user selects a number lower than
32, in which case the code should return 32.
Examples:
User selects 100, the code would return 72.
User selects 480, the code would return 400.
User selects 25, the code would return 32.
Currently the numbers are stored in a simple list, but I have control over
that list and they can be in whatever format makes the most sense. One
caveat is that they need to stay in code (so no database interaction).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion 8 - Build next generation apps
today, with easy PDF and Ajax features - download now
http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290039
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4