Is there a way to round smaller currency sub-units to regular ones, so as to minimize the rounding error? I've come across things like stochastic rounding but I don't know how I would apply it to my case (and I just know how much slack I'm going to get for that).
My use case is as follows:
User wanted to buy 20 XYZ at 1.1387. The total price should be 22.77.
In my system, a large order can be broken down into smaller orders:
Amount | Rate | Price
9.50 | 1.1387 | 10.82
9.50 | 1.1387 | 10.82
1.00 | 1.1387 | 1.14
The total amounts to 22.78 due to standard rounding (0-4 down, 5-9 up), whereas it should have been 22.77, which means I tell my user I have deducted 0.01 more than they owed me.
I've looked into using a smaller sub-unit, as recommended here, but I still have to round at some point, even if it is the last point in my calculations, which would cause confusion for users when things don't add up (Client requires strict adherence to currency decimals).
EDIT: I ended up keeping track of the nonsignificant figures and accumulating them until they become significant enough to merit rounding up, i.e. greater than or equal to 0.01 in this case.