如何在cassandra中存储6位数精度的双精度数字/浮点数字/十进制数字?

时间:2018-12-21 13:04:15

标签: cassandra datastax-enterprise databricks

我正在尝试在cassandra表中存储数据帧的某些字符串。 我尝试使用定义为float / double / decimal的cassandra表列。

但是每种类型仅存储2个精度,即8.00005作为8.00存储 69.345和69.34一样,cassandra表出了什么问题?为什么它不保存所有精度数字。如何解决这个问题?让我知道是否需要更多有关该问题的信息。

1 个答案:

答案 0 :(得分:2)

此问题似乎与cqlsh的精度设置有关。 cassandra可以正确存储值,但是当您通过cqlsh查询时,精度点设置会将其四舍五入。

了解有关精度点的cqlshrc选项的更多信息:cqlshrc

以下是默认的cqlshrc设置:

SimonWedgeView

检查以下示例:

;; 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

在设置float_precision之前选择:

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

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

将float_precision设置为6后选择:

select * from temp;

 id | val
----+---------
 1 | 1.23457
相关问题