In cassandra when to use decimal Vs float/double?
Asked Answered
A

2

8

I am using apache cassandra 3.x version. I am bit confused regarding when should I use decimal vs float types?

Is there any specific use-cases/differences when should go for float or avoid decimal and vice-versa?

I have gone through some quick tutorial none covered this difference. can anyone help me understand this ?

Ation answered 18/10, 2019 at 12:2 Comment(0)
V
12

From the book Learning Apache Cassandra By Mat Brown:

Cassandra has three types that store non-integer numbers:

  • The float type stores 32-bit IEEE-754 floating point numbers.
  • The double type stores 64-bit IEEE-754 floating point numbers.
  • The decimal type stores variable-precision decimal numbers, with no upper bound on size. Unlike a floating point number, a variable-precision decimal will never suffer from base 10 rounding errors in the fractional part of the number.

But decimal is likely to take up more space compared to other two. So, if it is a matter of precision, you can go for decimal. Otherwise, float/double are good enough in most of the cases.

Vibraculum answered 21/10, 2019 at 11:4 Comment(1)
Do you know how much more processing time it takes for decimal place addition or re-writes versus say a bigint?Caption
B
2

My observation was that float at max holds value 5 digits after decimal beyond that it approximates it. Ex if you have 1.00001 it would get inserted as it is but if you have 1.000001 it's inserted as 1 . It rounds up based on precision. If you have clear idea about about mantisa and precision (how many digits before and how many digits after decimal ) you can go with decimal . (Float and double behave the same way) .

Blame answered 29/11, 2019 at 13:43 Comment(2)
Bumped on this answer from someone, it says that Cassandra actually stores 6 digits. Testing that. #53885781Outsmart
@Outsmart thaks for sharing , it was helpful .Blame

© 2022 - 2024 — McMap. All rights reserved.