How to store 6 digit precision double/float/decimal number in cassandra?
Asked Answered
M

1

1

I am trying to store some strings of a dataframe in cassandra table. I tried with cassandra table columns defining as float/double/decimal.

But every type only storing 2 precision , i.e. 8.00005 as stored as 8.00 69.345 as 69.34 , what is wrong with cassandra table? Why it is not holding all precision digits. How fix this issue ? Let me know if needed any more information of the problem.

Melchor answered 21/12, 2018 at 13:4 Comment(1)
@AlexOtta , sir can you comment on this?Melchor
P
3

This issue seeme to be with the precision settings for cqlsh. The cassandra is storing the values properly , but when you query it through cqlsh , the precision point settings are rounding it off.

Read about the cqlshrc options about the precision points for more information : cqlshrc

The following are the default cqlshrc settings :

;; The number of digits displayed after the decimal point for single and double 
precision numbers
;; (note that increasing this to large numbers can result in unusual values)
;float_precision = 5

Check the following example :

create table temp(id int , "val" float ,PRIMARY KEY (id));

insert into temp(id,val) values(1,1.234567);

Select before setting float_precision :

select * from temp;

 id | val
----+---------
 1 | 1.23457

Select after setting float_precision to 6 :

select * from temp;

 id | val
----+----------
 1 | 1.234567
Paff answered 27/12, 2018 at 6:37 Comment(2)
how to set float_precision , at the time of table creation ?Melchor
@user3252097 The value is stored with proper precision in the table.Its just when it is displayed that the value is rounded off. With the specified setting you change what precision to be set during the display of the result. It is not a table level property.Paff

© 2022 - 2024 — McMap. All rights reserved.