I have an Android app that I'm handling money in. I heard that BigDecimal was the best for handling money and I was having trouble dealing with string representation of different currencies, so I switched from float to BigDecimal. However, I've run into a problem. If I store my BigDecimals in my SQL table as STRINGs, I can't run SUM() on them! I could pull the entries out in a cursor and sum them programmatically, but is there a better way to do this?
EDIT: I switched to NUMBER type, but now I'm running into a problem where the SUM() function gives me a float and when I convert that to BigDecimal I get extra garbage extended onto the end.
I think I solved it. I used the TOTAL() aggregate function of of SQLite to get the sum represented as a float, then used Float.toString() and then threw that into a new BigDecimal.
BigDecimal total = new BigDecimal(Float.toString(cur.getFloat(0)));