impala 四舍五入后转换成string后又变成一个double的数值解决(除不尽的情况)
例如Query: select cast(round(2 / 3, 4)*100 as string)+---------------------------------------+| cast(round(2 / 3, 4) * 100 as string) |+---------------------------------------+| 66.670000000000002 |+---------------------------------------+改成Query: select concat(cast(cast(round(2 / 3, 4) * 100 as decimal(9,2)) as string) ,'%')+--------------------------------------------------------------------------+| concat(cast(cast(round(2 / 3, 4) * 100 as decimal(9,2)) as string), '%') |+--------------------------------------------------------------------------+| 66.67% |+--------------------------------------------------------------------------+decimal(9,2) : 9表示位数,2表示小数精度。decimal最大精度是38
有效位:±1.0 × 10(-28次方) 到 ±7.9 × 10(28次方) 精度:28 到 29 位2. decimal ,float,double 差别
mysql中存在float,double等非标准数据类型,也有decimal这种标准数据类型。其区别在于,float,double等非标准类型,在DB中保存的是近似值,而Decimal则以字符串的形式保存数值。数据定义