Closed ChristopherDrum closed 3 years ago
Thanks for reporting.will look into it and get back within 48 hours.
As I look further, here are more incorrect cases.
bigDecimal.divide('2', '.0383292'))
Expected: 52.17953935902653851371800089748
Actual: 0.0000052179
bigDecimal.divide('.102', '.0383292',8))
Expected: 2.66115650731035
Actual: 0.00000027
So far, it seems to occur when the divisor has more decimal places than the dividend 🤔 But there may be more cases I've yet to discover.
I was able to repair all known issues in my own (Lua) code around the parsing of dividend decimal shift around decimal.ts, Line 29. My fix can't translate well to what you're doing, but conceptually that was the issue.
I am looking into it, but for now, I have found a workaround. If you add the leading zeros, like 0.102
or 0.123456
, it seems to work fine.
Checkout the latest patch v1.3.2
Leading zero... ah, sorry, that just didn't cross my mind to try. Thanks for the repair, looks good 👍
Describe the bug
bigDecimal.divide('123456789.123456','.0123456',18)
returns1000.006391940902021773
but should return10000063919.40902021773
Decimal position is wrong.
Additional context Using
npm
install in node; reports version1.3.1
Was working on an translation ofjs-big-decimal
to Lua (for Pico8) and my code returned the incorrect answer. Verified my answer againstjs-big-decimal
and realized I had perfectly implemented it, down to even this bug. 🐛