2022 Archives by date, by thread · List index

# Re: [libreoffice-users] ROUND function consistency

```=https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/round-function

Was the page I found that mentioned it, but other pages
didn't mention the banking rounding? So not sure if excell
would use regular rounding in excell, but uses the
excell so no way to test, and might even vary depending
on what version of excell and/or windows??

Note

This VBA function returns something commonly
referred to as bankers rounding. So be careful
before using this function. For more predictable
results, use Worksheet Round functions in Excel
VBA.

Note sure why neither Calc or Excell give option to select
which type of rounding to use?

Made a test formula to do it.
=IF(AND(RIGHT(TEXT(A1,&quot;##.0000"),2)="50",ISEVEN(INT(A1*100))=1),INT(A1*100)/100,ROUND(A1,2))

That looked at 3 and 4 digits and would round down for 0
to 49 and round up for 51 to 99. 50 would depend on the
original digit to 2nd decimal being even or odd to
determine.

=IF(AND(RIGHT(TEXT(A1,&quot;##.000"),1)="5",ISEVEN(INT(A1*100))=1),INT(A1*100)/100,ROUND(A1,2))
Would work with just looking at 3 digit, and would do same for 0 to 4, and 6 to
9, and then vary if 3rd was 5?

Might be another way, but that seemed to work..

On 5 Jun 2022 at 12:49, Johnny Rosenberg wrote:

From: &#160;Johnny Rosenberg
<gurus.knugum@gmail.com>
Date sent:60;Sun, 5 Jun 2022 12:49:42 +0200
Subject: ;Re: [libreoffice-users] ROUND function
consistency
To: 0;LibreOffice Användare
<users@global.libreoffice.org>

```
```Den sön 5 juni 2022 kl 11:55 skrev Michael D. Setzer II <;msetzerii@gmail.com
```
```:
```
```
```
```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..> >
```
```
Oh, yes. I didn't think of that. Yes, that makes sense, and I remember we
learned that method in school too. So no bug report necessary, then\u2026 Unless
we want the documentation to be clearer on this.</div>>

Kind regards

Johnny Rosenberg

```
```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:        &#160;     Sun, 5 Jun 2022 11:37:04 +0200> > Subject:        60;       Re:
[libreoffice-users] ROUND function
consistency
To:         &#160;           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/

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

+------------------------------------------------------------+
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
https://www.documentfoundation.org/privacy
```
```

+------------------------------------------------------------+
Michael D. Setzer II - Computer Science Instructor (Retired)   60;
mailto:mikes@guam.net                      &#160;
mailto:msetzerii@gmail.com
Guam - Where America's Day Begins                    &#160;
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/