<cfcomponent>

        <cffunction name="split" access="public" returntype="array">

                <cfargument name="bill"  type="numeric" required="yes" >

        <cfargument name="people"  type="numeric" required="yes" >

        <cfset var returncosts = ArrayNew(1)>

        <cfset var tallytest = 0>

        <cfset var cost = decimalformat(arguments.bill/arguments.people)>

        <!--- Get pennies that we are short if any --->

        <cfset var diff = (bill - (cost*arguments.people))*100>

               

                <!--- Creat the array of costs --->

        <cfloop from="1" to="#arguments.people#" index="i">

                <cfset arrayappend(returncosts,cost)>

        </cfloop>

        <!--- Spread out the diff --->

        <cfloop from="1" to="#abs(diff) + 1#" index="i">

                <cfif diff gt 0>

                        <cfset returncosts[i] = returncosts[i] + .01>

            <cfelse>

                    <cfset returncosts[i] = returncosts[i] - .01>

            </cfif>

        </cfloop>

       

        <!--- Testing purposes only lets make sure we are adding back up to bill --->

        <cfloop from="1" to="#arguments.people#" index="i">

                <cfset tallytest = tallytest + returncosts[i]>

        </cfloop>

        <cfset arrayappend(returncosts,diff)>

        <cfset arrayappend(returncosts,tallytest)>

               <cfreturn returncosts>

        </cffunction>

</cfcomponent>