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.edmo...@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+unsubscr...@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+unsubscr...@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

Reply via email to