Storing currency values in SQLite3

前端 未结 5 1351
萌比男神i
萌比男神i 2020-12-15 22:26

I\'m dealing with lots of different currencies in my application, and I want to know what the \"best\" way is to store them in an SQLite3 database.

I\'m leaning towa

5条回答
  •  清酒与你
    2020-12-15 22:53

    SQLite has no BigDecimal field So I use the SQLite Integer type and convert like so: BigDecimal bd = new BigDecimal("1234.5678"); int packedInt = bd.scaleByPowerOfTen(4).intValue(); // packedInt now = 12345678 Now save packedInt to SQLite Integer field. To go back to BigDecimal: BigDecimal bd = new BigDecimal(packedInt); // bd = 12345678 bd = bd.scaleByPowerOfTen(-4); // now bd = 1234.5678

提交回复
热议问题