问题
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