Thanks for the tips, Ben...

> -----Original Message-----
> From: Ben Doom [mailto:[EMAIL PROTECTED]
> Sent: Thursday, November 01, 2007 2:42 PM
> To: CF-Talk
> Subject: Re: How to break down a number into percentages
> 
> Without seeing your code, I can say this with a fair degree of
> certainty:  if you're really losing 3%, you are probably doing something
> wrong (like always truncating, using integers instead of floats, etc.).
> 
> If you round to the nearest cent, you should be getting totals like
> $99.97 or $100.02 when you run your functions.  Getting something exact
> is actually a bit difficult, unless the percentages happen to be even
> divisors of the beginning amount (which, for $100, they probably are,
> but we'll ignore that since we're using fake numbers).
> 
> One way banks tackle this is by alternating fraction increases and
> decreases.  For example, the first time they get a fraction of a cent,
> they go up to the next penny.  The second time, they go down.  The third
> time, up again, and so forth.  It's not perfect, but it makes the math
> easy, and you should never be more than a penny off.
> 
> --Ben Doom
> 
> Rick Faircloth wrote:
> > Hi, all.
> >
> > I know that sounds simple and, as it's stated, it is.
> >
> > However, what I'm trying to accomplish turns out to be more
> > complicated that I thought.
> >
> > I want to take a dollar amount, break it down by various percentages
> > (that should total 100%), then place the dollar amounts into various
> > accounts and have the total placed into those accounts equal the
> > original amount that was broken down by the percentages.
> >
> > I've been trying every function I could find including decimal, round,
> > various math equations, to achieve the goal, but it's not working.
> >
> > The data type in myself is decimal, set to 2 places, but invariably,
> > if I take $100 and run it through the breakdown and place the amounts
> > into the accounts, then add the dollar figures places into the accounts,
> > the total comes back $97.00.  Not only that, but all dollar amounts ending
> > up in the database are whole dollar amounts with not cents.
> >
> > Anybody have any clues how this should be approached?
> >
> > If the description above is not sufficient, I can give some concrete
> > examples with actual numbers, but I figured someone had tackled
> > something like this before.
> >
> > Thanks,
> >
> > Rick
> >
> > PS - I am on CF 8 now, so every solution is in play!  :o)
> >
> >
> >
> >
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Enterprise web applications, build robust, secure 
scalable apps today - Try it now ColdFusion Today
ColdFusion 8 beta - Build next generation apps

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:292520
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to