• impala 四舍五入后转换成string后又变成一个double的数值解决(除不尽的情况)


    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则以字符串的形式保存数值。
    数据定义

  • 相关阅读:
    解除win7系统静音
    temp--test audio micphone
    2015年年中总结
    通过对象成员地址求对象本身地址
    管理全局对象
    UTF-8 <==> unicode(WCHAR)
    [HEOI2016/TJOI2016]树
    P2382 化学分子式
    [PKUWC2018]Slay the Spire
    [Ynoi2019模拟赛]Yuno loves sqrt technology III
  • 原文地址:https://www.cnblogs.com/gavinYang/p/11196412.html
Copyright © 2020-2023  润新知