<html>
    <head>
      <base href="https://bugs.documentfoundation.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_UNCONFIRMED "
   title="UNCONFIRMED - Basic: Round VBA compatibility function implements wrong rounding mode"
   href="https://bugs.documentfoundation.org/show_bug.cgi?id=142922">142922</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Basic: Round VBA compatibility function implements wrong rounding mode
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>LibreOffice
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>UNCONFIRMED
          </td>
        </tr>

        <tr>
          <th>Keywords</th>
          <td>implementationError
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>BASIC
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>libreoffice-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mikekaganski@hotmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>As explained in VBA documentation for Round [1]:

<span class="quote">> This VBA function returns something commonly referred to as bankers rounding.</span >

[MS-VBAL] [2] defined Banker's rounding as alternative name for
"round-to-even"; it is one of rounding modes defined in IEEE 754, its
recommended rounding mode for decimal [3].

[1] also provides some examples demonstrating the values returned bu VBA's
Round:

<span class="quote">> ?Round(0.12335,4)
>  0,1234
> ?Round(0.12345,4)
>  0,1234
> ?Round(0.12355,4)
>  0,1236
> ?Round(0.12365,4)
>  0,1236</span >

However, LibreOffice's Round function [4] implementation [5] does not implement
the required rounding mode. Executing the example calculations mentioned above
gives 0.1234, 0.1235, 0.1236, 0.1237.

FTR: we have a rtl_math_round function, that accepts a flag defining rounding
mode, rtl_math_RoundingMode_HalfEven among the possible values, which may be
used in the VBA function implementation.

[1]
<a href="https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/round-function">https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/round-function</a>

[2]
<a href="https://docs.microsoft.com/en-us/openspecs/microsoft_general_purpose_programming_languages/ms-vbal/98152b5a-4d86-4acb-b875-66cb1f49433e">https://docs.microsoft.com/en-us/openspecs/microsoft_general_purpose_programming_languages/ms-vbal/98152b5a-4d86-4acb-b875-66cb1f49433e</a>

[3] <a href="https://en.wikipedia.org/wiki/IEEE_754#Rounding_rules">https://en.wikipedia.org/wiki/IEEE_754#Rounding_rules</a>

[4]
<a href="https://help.libreoffice.org/7.2/en-US/text/sbasic/shared/03170000.html?DbPAR=BASIC">https://help.libreoffice.org/7.2/en-US/text/sbasic/shared/03170000.html?DbPAR=BASIC</a>

[5]
<a href="https://opengrok.libreoffice.org/xref/core/basic/source/runtime/methods1.cxx?r=86d298f8&mo=63707&fi=2377#2377">https://opengrok.libreoffice.org/xref/core/basic/source/runtime/methods1.cxx?r=86d298f8&mo=63707&fi=2377#2377</a>

[6]
<a href="https://opengrok.libreoffice.org/xref/core/sal/rtl/math.cxx?r=49af7e22&mo=38462&fi=1130#1130">https://opengrok.libreoffice.org/xref/core/sal/rtl/math.cxx?r=49af7e22&mo=38462&fi=1130#1130</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>