Guest User

Split the Bill

a guest
Dec 1st, 2012
122
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <cfscript>
  2.    
  3.     function splitBill(total,partysize) {
  4.         var party = ArrayNew(1);
  5.         var extra = 0;
  6.         var loser = 0;
  7.  
  8.         if((total OR partysize) LTE 0)
  9.             return party;
  10.  
  11.         for(i = 0;i LTE partysize-1; i=i+1) {
  12.             ArrayAppend(party,numberFormat((total/partysize),".00"))
  13.         }
  14.  
  15.         extra = total - ArraySum(party);
  16.         loser = randRange(1, partysize, 'SHA1PRNG');
  17.         party[loser] = NumberFormat(party[loser] + extra,".00");
  18.  
  19.         return party;
  20.     }
  21.  
  22. </cfscript>
RAW Paste Data