6

I'm trying to get a Double value from a Cassandra table with a double type column. I've created the table in CQL3 syntax:

CREATE TABLE data_double (
    datetime timestamp,
    value double,
    primary key (datetime)
    );

I've inserted a row:

INSERT INTO data_double (datetime,  value) VALUES ('111111111', 123.456);  

When I do:

SELECT * from data_double;

I get that the value is 123.46

Why is the value rounded?

Thanks

Kyle Hale
  • 7,912
  • 1
  • 37
  • 58
Guy Wald
  • 599
  • 1
  • 10
  • 25

1 Answers1

11

The cqlsh utility by default will only display 5 digits of precision for floating point numbers.

You can increase this by creating a cqlshrc file with contents like the following:

[ui]
float_precision = 10

The cqlsh docs page provides more details on the available options.

Update: The location of the cqlshrc file changed at some point in Cassandra. The new default location is ~/.cassandra/cqlshrc. You can also use a file in a different location with the --cqlshrc command-line option.

BrianC
  • 10,591
  • 2
  • 30
  • 50
  • Are you sure its `. cqlshrc ` ? datastax referes to it as `cqlshrc ` here https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlshUsingCqlshrc.html?hl=cqlshrc – simo Feb 23 '17 at 14:53
  • @simo thanks for pointing that out; the location did change somewhere along the way, so I've edited my answer to be more clear. – BrianC Feb 23 '17 at 22:09
  • so there's no way to this within the select statement? – The other other Alan Mar 20 '17 at 21:35
  • 1
    @AFischbein no there isn't; the cqlshrc file is the only way I'm aware of. Keep in mind this is just the cqlsh shell behavior; when you run with your own application the driver will return the full precision of all floating values. – BrianC Mar 20 '17 at 22:04