Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing currency in SQlite android database

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.

like image 484
Muhammad Umar Avatar asked Feb 08 '12 03:02

Muhammad Umar


1 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.

like image 141
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz Avatar answered Sep 20 '22 20:09

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz