Apache OpenOffice (AOO) Bugzilla – Issue 107277
basic: adding currency values overflows when result > (2^31)/10000
Last modified: 2017-05-20 10:47:55 UTC
Try the code below. When you add 2 Currency values and the result is bigger than (2^31)/10000 the number you get is not expected, is like an overflow. It does not matter if the numbers you are adding are smaller or bigger than (2^31)/10000 (like problems because the result needs more than 4 bytes) (3 different patterns to choose in the code by removing REMs) I guess this bug should also happen in other OSs REM ***** BASIC ***** REM P0WER(2;31) = 2.147.483.648 (using the "." as thousand separator) REM POWER(2;31)/10000 = 214.748,3648 Const inc As Currency = 1 Const basenumber As Currency = 214745 Const topnumber As Currency = 214750 REM Const inc As Currency = 2000 REM Const basenumber As Currency = 300000 REM Const topnumber As Currency = 310000 REM Const inc As Currency = 300000 REM Const basenumber As Currency = 300000 REM Const topnumber As Currency = 1000000 Sub Main Dim NewTotalPrice As Currency Dim OldTotalPrice As Currency OldTotalPrice = basenumber Do While OldTotalPrice < topnumber NewTotalPrice = OldTotalPrice + inc MsgBox "Adding " & inc & " to " + OldTotalPrice + " results " & NewTotalPrice OldTotalPrice = NewTotalPrice Loop End Sub
It is uglier than you think. Try this : Dim a As Currency a = 300000 MsgBox( a ) a = a + 0.0000 MsgBox( a ) ' My PC displays : 75632326542153.2672 Don't use Currency, it is completely bugged. See Issue 31001 See Issue 54049 See Issue 91121
Andrease, please have a look.
STARTED, 3.x
Reset assigne to the default "issues@openoffice.apache.org".