3 ms·
What's wrong with storing it as a float? I'm not saying you're wrong, I just genuinely don't know. If you could explain/point me to relevant literature I'd be g
by esbwhat 14y ago
What's wrong with storing it as a float? I'm not saying you're wrong, I just genuinely don't know. If you could explain/point me to relevant literature I'd be grateful.
- drivebyacct2 14y agoQuick Google, sorry it's easier than me offering an incomplete explanation: http://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency http://stackoverflow.com/questions/3730019/why-not-use-doubl... And I really don't mean to pick on you, but that this isn't better known is why I worry when I see random sites popup offering financial services.
- esbwhat 14y agoThat's okay. I don't think I'm really representative anyway, as I'm not a professional/schooled programmer. Thanks for the link, I did try googling it myself but I didn't think to use the word "currency" so I just got a bunch of irrelevant results.
- wmf 14y agohttp://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency http://stackoverflow.com/questions/3730019/why-not-use-doubl... Also, all Bitcoin calculations are supposed to be done in integer Satoshis.
- pygy_ 14y agoSome numbers with a finite representation in base 10, 0.2, for example, don't have a finite representation in base 2. They are rounded, and doing arithmetic on such numbers leads to compounded rounding errors that you don't want to see when dealing with money. Another problem is that the mantissa of floating point numbers is limited (52 bits for doubles), which can lead to truncated numbers, another big no no.
- dsterry 14y agoStoring BTC balances as floats is something a few services have done in the past so it makes sense to ask/bring up. Since BTC have 8 decimal precision, rounding can become noticeable very quickly even in addition and subtraction even though in real, today's value, it's not such a big deal.