Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to define float decimal precision in Android Room table column

I know in sqlite we can define column decimal precision with DECIMAL(10,2)
How can this be achieved with Android Room

Eg. I want room table column to store 1000.33, when I insert 1000.3333333333

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You cannot define the precision.

All REAL (the storage class used for decimal/float/double values) values are stored in SQLite as an 8-byte IEEE floating point number. An alternative approach would be store the value as a String BUT not a String that can be considered a numeric e.g. (as it would be stored as such) you could store the value D1000.33. i.e. the D ensures that the value is stored/retrieved as a String.

You need to apply the required precision when (e.g. using the SQLite round function) or after you extract the value.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading