Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index

On 07/19/2013 07:26 PM, toodr wrote:
I had the same problem. I needed to implement the so called Bankers' Rounding
Function, which would round with respect to the 4/5 rule. And finally I
ended doing it myself in a short Function in LO Basic. I tried my best,
although math  and programming are not my strong sides. So here it is,
together with a Subroutine called "rounded_test" and the very Function is
called "Rounded".
>>> A whole bunch of code stripped out here <<<

You can call it for each line (item) in an invoice. It will take the number
you through at it and will return it rounded to the second diggit after the
comma or point separator. Then when you sum the invoice up - the numbers
will always be consistent and correctly rounded.

This is not the best of programming though, but it works.
I hope it will help someone.
Feel free to modify and use it as you please.

Just one point I would like to make. If you are working with money be sure that the total of the rounded amounts adds up to match the original amount.


$5.39 divided among several accounts.

10.5% to Acct A = 0.56595  => $0.57
13.5% to Acct B = 0.72765  => $0.73
17%   to Acct C = 0.9163   => $0.92
59%   to Acct D = 3.1801   => $3.18
                      Total = $5.40

Any summing error needs to be accounted for if you ever want your accounts to balance.

   ^ ^  Mark LaPierre
Registered Linux user No #267004

To unsubscribe e-mail to:
Posting guidelines + more:
List archive:
All messages sent to this list will be publicly archived and cannot be deleted


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.