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


I just performed a bit of a test.
Cells across.
A1| =RANDBETWEEN(0,100000)/100  # simulate dollar and cent amounts between 0.00 and $1000.00
B1| =A1*0.15                    # simulate a tax of 15% on the amounts in A
C1| =ROUND(B1,2)                # round the tax amount to 2 places (whole cents) using the Calc ROUND function D1| =VBRND(B1,2)                # round the tax to 2 places using a macro function that uses the VBA compatible round function (bankers rounding)
E1| =INT(B1*100+0.5)/100        # round the tax the old school way.

Function VBRND(c,d)
VBRND = round(c,d)
End Function

I then copied this row down another 999 rows and performed some summation at the bottom of the 1000 results. I regenerated the random values in A ten times and recorded the summations below.

(sum RNDBETWEEN) * 0.15 sum (RNDBETWEEN * 0.15) Sum ROUND() ABS error ROUND() sum VBRND() ABS error VBRND() sum int(val*100+0.5)/100 ABS Error old school 75056.829 75056.829 75057.07 0.24100000000908 75056.74 0.089000 75057.07 0.24100000000908 75388.419 75388.419 75388.59 0.171000000002095 75388.4 0.019000 75388.59 0.171000000002095 74833.6095 74833.6095 74833.83 0.220499999995809 74833.44 0.169500 74833.83 0.220499999995809 73028.487 73028.487 73028.76 0.273000000001048 73028.42 0.067000 73028.76 0.273000000001048 73042.698 73042.698 73042.95 0.251999999993131 73042.69 0.008000 73042.95 0.251999999993131 74173.5075 74173.5075 74173.8 0.292499999995925 74173.46 0.047500 74173.8 0.292499999995925 75420.3825 75420.3825 75420.64 0.257499999992433 75420.4 0.017500 75420.64 0.257499999992433 74621.5965 74621.5965 74621.85 0.25350000000617 74621.55 0.046500 74621.85 0.25350000000617 75481.0995 75481.0995 75481.41 0.310500000006868 75481.12 0.020500 75481.41 0.310500000006868 73694.1585 73694.1585 73694.39 0.231499999994412 73694.03 0.128500 73694.39 0.231499999994412

        
Av. Err. 0.250299999999697 Av. Err. 0.061300 Av. Err. 0.250299999999697

        
        Std. Dev.       0.038875        Std. Dev.       0.053381        Std. Dev.       0.038875




I found that the average magnitude of the error was least with the bankers rounding although this ad a little more spread. Bankers rounding also had less bias.

Steve

On 05/06/2022 21:55, Michael D. Setzer II wrote:
One windows excell page mentions that it uses the
banking rounding method, which I believe is the round to
nearest even. So, using that method 12.125 would round
to 12.12, while 12.135 would round to 12.14..
With this method if next digit is 1,2,3,4 the number
rounds down. If it is 6,7,8,9 it rounds up. If 0 it does
nothing, but if it is 5, it has to check if the key pervious
digit is an even or old number. If it is even, then it rounds
down, if odd it rounds up.

The regular LibreOffice round uses the standard round
function.

Usually, the standard round is used, but know that some
government regulations require the banking/roundeven
or roundodd method.

Was surprized that excell's would default to banking?
Note sure why they don't provide one for each method, or
have an option to set.



On 5 Jun 2022 at 11:37, Johnny Rosenberg wrote:

From:                   Johnny Rosenberg
<gurus.knugum@gmail.com>
Date sent:              Sun, 5 Jun 2022 11:37:04 +0200
Subject:                Re: [libreoffice-users] ROUND function
consistency
To:                     LibreOffice Användare
<users@global.libreoffice.org>

Looks like a bug to me. 12.125 returns 12.12, but 12.1251 returns 12.13.
Both should return the same.
I guess this bug should be reported.
Meanwhile, you can make your own function that you can use. Here are two
different suggestions.

1: This one use the Calc built-in ROUND() cell function. Place it in "My
macros & dialogs". VBA compatibility mode is not needed.

Public Function faRound(x As Double, d As Integer)
Dim Calc
Calc=createUnoService("com.sun.star.sheet.FunctionAccess")
faRound=Calc.callFunction("ROUND", Array(x, d))
End Function

2: This one use the method we learned at school:
Public Function fRound(x As Double, d As Integer)
fRound=Int(10^d*x+.5)/10^d
End Function

Test:
Print afRound(12.125, 2)
Result: 12.13

Print fRound(12.125, 2)
Result: 12.13

Print fRound(12.125, 1)
Result: 12.1

... and so on.

Kind regards

Johnny Rosenberg

Den sön 5 juni 2022 kl 04:46 skrev Steve Edmonds <steve.edmonds@ptglobal.com
:
I have just put a basic macro together so it will calculate income tax
due from our local tax rates.
I needed to round the tax to the nearest cent so taking the easy route I
added Option VBASupport 1 to use the available VB round function.

I then noticed that the VB round function with say round(12.125,2)
rounds down to 12.12 and the LO inbuilt spread sheet function ROUND with
ROUND(12.125,2) rounds up to 12.13.

Is rounding in this situation arbitrary or is there some some convention
for consistency.

Steve


--
To unsubscribe e-mail to:users+unsubscribe@global.libreoffice.org
Problems?
https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more:https://wiki.documentfoundation.org/Netiquette
List archive:https://listarchives.libreoffice.org/global/users/
Privacy Policy:https://www.documentfoundation.org/privacy

--
To unsubscribe e-mail to:users+unsubscribe@global.libreoffice.org
Problems?https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more:https://wiki.documentfoundation.org/Netiquette
List archive:https://listarchives.libreoffice.org/global/users/
Privacy Policy:https://www.documentfoundation.org/privacy

+------------------------------------------------------------+
  Michael D. Setzer II - Computer Science Instructor
(Retired)
mailto:mikes@guam.net mailto:msetzerii@gmail.com
  Guam - Where America's Day Begins
  G4L Disk Imaging Project maintainer
  http://sourceforge.net/projects/g4l/
+------------------------------------------------------------+





--
To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy

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.