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

At 16:26 19/07/2013 -0700, Todor Takov wrote:
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".

[Over 120 lines of code snipped]

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

Isn't this somewhat overkill? If you need just to round to the second fractional place - dollars and cents, pounds and pence, whatever - the only exception is the case where the third fractional place is 5 and the second fractional place is even. In that case you need ROUNDDOWN(); in all other cases, ROUND() will do the job:


(And yes: this works for negative values, too.)

Brian Barker

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.