|
Hi Booth -
Secondly, Ken's solution looks too simple.
My solution is simple because the whole thing is simple. It's just custom rounding with a couple extra things tossed in to do the fee calculation.
Here's what I tried this morning and it seems to work, but it doesn't use the %div bif, which requires whole numbers.
Okay, if %div won't compile with non-integers (I didn't try to compile my code), this should work. The key is to divide with truncation after adding the custom rounding factor.
fee = 4 * %int( ( amount + 499.99 ) / 500.00 )
Amount + 499.99 / 500.00 %int Fee
.00 499.99 0.99998 0 .00
.01 500.00 1.00000 1 4.00
500.00 999.99 1.99998 1 4.00
500.01 1000.00 2.00000 2 8.00
1000.00 1499.99 2.99998 2 8.00
1001.00 1500.00 3.00000 3 12.00
As you can see, this handles all boundaries cases properly.
Simple, yes, but it actually works properly in a way that is clear if you
think about it.
Ken http://www.ke9nr.net/ Opinions expressed are my own and do not necessarily represent the views of my employer or anyone in their right mind.
This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.