2013 Archives by date, by thread · List index

# [libreoffice-users] Re: Visible currency rounding

```On 20-07-2013 01:26, toodr wrote:
```
```I had the same problem. I needed to implement the so called Bankers' Rounding
Function,
```
```
http://en.wikipedia.org/wiki/Rounding
Round half to even
A tie-breaking rule that is less biased is round half to even, namely:
If the fraction of y is 0.5, then q is the even integer nearest to y.
```
Thus, for example, +23.5 becomes +24, as does +24.5; while −23.5 becomes −24, as does −24.5. This method treats positive and negative values symmetrically, and is therefore free of sign bias. More importantly, for reasonable distributions of y values, the expected (average) value of the rounded numbers is the same as that of the original numbers. However, this rule will introduce a towards-zero bias for even numbers (including zero), and a towards-infinity bias for odd ones. This variant of the round-to-nearest method is also called unbiased rounding, convergent rounding, statistician's rounding, Dutch rounding, Gaussian rounding, odd-even rounding,[3] bankers' rounding or broken rounding, and is widely used in bookkeeping. This is the default rounding mode used in IEEE 754 computing functions and operators.
```
This means that your function does not work correctly i.e.
23,574 should be rounded to 23,58, you function gives 23,57

so, i tried to create a function hwich lives up to my expectations... ;)
(but i NEVER used 'Bankers' Rounding'......)

function bround(i as double, Optional d as integer)
dim format as string
dim tmp as string
dim c as double
svc=createUnoService("com.sun.star.sheet.FunctionAccess")
if IsMissing(d) then d=2
bround = svc.callFunction("ROUND", array(i/2, d))*2
end function

--
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
```

### Context

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.