Closed GoogleCodeExporter closed 9 years ago
I am very much against the use of double, because it is a floating point
format, which can introduce rounding errors. Floating points should never be
used in financial transaction systems.
If you want to calculate in BTC (as opposed to microcents/nanocoins/satoshi),
you should be doing this in BigDecimal. It seems that some work for a converter
utility class is under way in
http://code.google.com/p/bitcoinj/issues/detail?id=23 as well.
Original comment by thilopl...@googlemail.com
on 9 Jun 2011 at 11:24
Allright, I am now using the expression
final BigInteger dollars = new BigDecimal(balance).multiply(new
BigDecimal(exchangeRate)).toBigInteger();
to calculate the dollar value. The only gripe I have is I have to
useUtils.bitcoinValueToFriendlyString(dollars)
in order to format my Dollars (!) for user reading. This feels awkward to me.
Also, I don't think that floats/doubles can be avoided completely. At some
point, we might interface into other projects/frameworks that don't support
BigInteger, like a charting tool.
Original comment by andreas....@gmail.com
on 10 Jun 2011 at 1:16
I think it would be best to keep bitcoinj dealing in exact values using
BitInteger, and leave further manipulation to the caller. You can always use
BigDecimal.doubleValue to convert to a double in the caller.
Original comment by mi...@google.com
on 10 Jun 2011 at 10:54
Integer calculations are the way to go. Introducing float or double for
currency is wrong on many levels.
Original comment by g.rowe.f...@gmail.com
on 12 Jun 2011 at 2:03
Staying with integers for now.
Original comment by mi...@google.com
on 23 Sep 2011 at 8:58
Original issue reported on code.google.com by
andreas....@gmail.com
on 9 Jun 2011 at 8:56