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:
=IF(AND(INT(MOD(ABS(Xn)*1000;10))=5;ISEVEN(Xn*100));ROUNDDOWN(Xn;2);ROUND(Xn;2)) (And yes: this works for negative values, too.) Brian Barker -- To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/ Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette List archive: http://listarchives.libreoffice.org/global/users/ All messages sent to this list will be publicly archived and cannot be deleted