Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

rajib76 avatar image
rajib76 asked alexandre.dutra answered

Will we lose precision if we use the double datatype?

We have a requirement to store two pieces of information in Cassandra one is quantity and the other is cost. We are planning to use DOUBLE as the datatype for these two fields. I wanted to see if it is recommended to choose double. Will we lose precision if we use DOUBLE?

cql
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Erick Ramirez avatar image
Erick Ramirez answered

A CQL double datatype is a 64-bit floating point so it can hold decimal values much larger than a regular float.

For quantity, you'll be better off using one of the CQL integer datatypes like int (32-bit) or bigint (64-bit).

For details, see the CQL Data types documentation. Cheers!

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

alexandre.dutra avatar image
alexandre.dutra answered

Expanding on what @Erick Ramirez said: for monetary amounts you want to use arbitrary-precision types. The best type for that in CQL is decimal. Never use floating-point types like float or double, these are best suited for scientific measures mostly.

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.