4

I have a problem. I am struggling to calculate programmatically the number of cryptocurrencies because I sometimes have inaccuracies in the last digit. Does anybody know what the problem is? (Of course, I have calculated the appropriate fees that need). For example, Binance uses accuracy for 8 Digits. What is the Rounding that they used? I would appreciate an answer if someone have the appropriate knowledge on this matter

RoundingMode.CEILING
RoundingMode.DOWN
RoundingMode.FLOOR
RoundingMode.HALF_DOWN
RoundingMode.HALF_EVEN
RoundingMode.HALF_UP
RoundingMode.UNNECESSARY
RoundingMode.UP
Andrew Chow
  • 67,209
  • 5
  • 76
  • 149
  • I am currently debugging exactly the same behaviour as you describe in this issue. My balance for ETH does not add up if compared to my own calculations. At the moment, I assume that Binance does not credit the full amount of the deposit (e.g. 14 decimal places) to the account balance, but strips it to the precision they internally use (e.g. 8 decimal places). If I thereby apply `RoundingMode.DOWN ` as rounding mode, my results become valid. I am still looking to get any confirmation on that though. – croeck Aug 31 '19 at 20:56

1 Answers1

0

There should not be any rounding because all operations are integer operations. The 8 digits is because they calculate using the base unit of Bitcoin, the satoshi, which is 0.00000001 Bitcoin (8 digits). It is calculated as an integer (i.e. calculation uses satoshis, not Bitcoin) multiplied by an integer for the number of bytes, thus the result will also be an integer. The decimal then comes back as they shift the decimal point to represent the value in Bitcoin. There is no rounding involved, if there is, you are doing something wrong.

Andrew Chow
  • 67,209
  • 5
  • 76
  • 149
  • Are you totally sure that Markets like Binance or Gdax.etc do the same calculation like this? – Panagiotis Drakatos May 10 '18 at 10:22
  • There is no reason not to do the calculation like this. If they do not do integer operations, then they introduce the possibility for floating point precision errors which can cause them to lost money for their customers. – Andrew Chow May 10 '18 at 15:21
  • Exchanges *do* have rounding errors. – Evert Feb 22 '19 at 17:29