我正在使用 apache cassandra 3.x 版本。我对什么时候应该使用小数和浮点类型感到有些困惑?
Is there any specific use-cases/differences when should go for float or avoid decimal and vice-versa?
我已经完成了一些快速教程,但没有涵盖这种差异。谁能帮我理解这一点?
最佳答案
来自本书学习 Apache Cassandra 马特·布朗:
Cassandra has three types that store non-integer numbers:
- The
float
type stores 32-bit IEEE-754 floating point numbers.- The
double
type stores 64-bit IEEE-754 floating point numbers.- The
decimal
type stores variable-precision decimal numbers, with no upper bound on size. Unlike a floating point number, a variable-precision decimal will never suffer from base 10 rounding errors in the fractional part of the number.
但与其他两个相比,十进制可能会占用更多空间。所以,如果是精度问题,你可以去
decimal
.否则,float
/double
在大多数情况下都足够好。
关于cassandra - 在 cassandra 中何时使用十进制与浮点/ double ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58450530/