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

…衆ロ難τιáo~ 提交于 2021-02-11 14:24:15

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/53885281/how-to-store-6-digit-precision-double-float-decimal-number-in-cassandra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!