官方介绍:
Data type with fixed precision and scale. A user can specify precision and scale by expression DECIMAL
(precision,scale) in a DDL
statement, for example, DECIMAL
(10,2). The maximum precision is 38 digits. Mapped to java.math.BigDecimal
. The binary representation is binary comparable, variable length format. When used in a row key, it is terminated with a null byte unless it is the last column.
Example:
DECIMAL
DECIMAL(10,2)
翻译成人话如下:
Phoenix 的 decimal 类型和 java 的 BigDecimal 类型是一回事, 用于表示不可变的、任意精度的有符号十进制数。
使用形式为: DECIMAL
(precision,scale)
可以设置两个参数: precision,scale
precision 表示精度, 也就是有效数字, 也可以说是整数部分加小数部分的位数
scale 表示保留小数的位数
工作中使用的时候遇到了一些问题, 记录一下.
1. 小数后面的0会自动省略
如: 类型: decimal(5,3) 存入数: 0.060, 实际会省略最后一位0, 保存的是0.06, 对位数有严格要求的情况下不适用
2. 遇到10的倍数的整数, 会自动以科学计数法保存数据
如: 类型 decimal(12,2) 存入数:13200.00 , 实际存的是 1.32E+4, 对格式有严格要求的也不行