mysql|base func

2020-04-28

mysql常用函数


round(num, d) 取整

  • num 需要取整的数字
  • d 表示四舍五入后保留的小数点后的位数;可取负数,针对左侧位置的数值进行保存
  • 案例
    • 两个方法相等: select round(156.123, 0) || seelct round(156.123)  ==》 156
    • d 取负数:            select round(156.123,-1)   ==》 160

floor(num) 向下取整,只返回整数部分,小数部分直接舍弃;不需要判断是否四舍五入

  • select round(156.1)   ==》 156
  • select round(156.6)   ==》 156

ceiling() 向上取整,只要存在小数部分,则返回num的整数部分 +1;

  • select round(156.1)   ==》 157
  • select round(156.6)   ==》 157

 

猜你喜欢

转载自www.cnblogs.com/bennyjane/p/12799177.html