Cassandra float precision

Viewed 791

I created float value from a Cassandra table with a float type column.

CREATE TABLE testing(
id int,
value float,
primary key (id)
);

INSERT INTO testing(id,  value) VALUES (1, 2341.1);  

SELECT * from testing;

I get that the value is 2341.1001

What's wrong with my setting? Thanks.

Here is my cassandra version.

cassandra@cqlsh> show version
[cqlsh 5.0.1 | Cassandra 3.11.1 | CQL spec 3.4.4 | Native protocol v4]
1 Answers

floats & doubles are represented in memory as close approximations to number that you specified as input. You can find more details about internal representation of floats and doubles in the Java language specification.

If you want to have precise numbers you can use decimal type, that is mapped into Java's BigDecimal type, but it use more memory/disk space.

Related