1. Ask algorithm from the client. It happens in different ways I think.
2. And the margin and Commission are one and the same mathematically.
3. For example, a typical margin of 2 percent is considered as "Sum * (100 + 2) / 100".
4. There are still questions - and when to round. With a single ruble. Or already on the whole amount. In most of the discrepancies are. Cm. paragraph 1.
5. Since the accuracy is known in advance, it is advisable to consider in the whole (by sliding the decimal point, that is, multiplying)