Home » Android » java – Storing currency in SQlite android database

java – Storing currency in SQlite android database

Posted by: admin June 15, 2020 Leave a comment


I am trying to store currency values in sqlite database in android. I don’t think so that int will be used here. I have heard that Bigdecimal can be used. If anyone can tell me the way it should be used to send values to sqlite database.

How to&Answers:

Store the BigDecimal as a String.

You can use the toPlainString() method.

BigDecimal b = new BigDecimal();
String s = b.toPlainString();

Then when you pull it from the database you can create a new BigDecimal.

BigDecimal c = new BigDecimal(String s)

Believe it or not SQLite 3.0 stores all data types as strings even if you say it should be an Integer. Take a look at this web page from the official SQLite website and scroll down to the “Manifest Typing and BLOB Support” section. It talks about how it will let you store strings in columns of other types.


Just use Int here. Since SQlite use 8 bytes for int, the max values is 2^64, which is 1.8446744e+19 – 1, more or less 10^18, big enough for the currency.

Also us