SQL 四舍五入 同时取规定小数位的数值

1.round(a,b) 函数是四舍五入用,第一个参数是我们要被操作的数据,第二个参数是设置我们四舍五入之后小数点后显示几位

2.numeric()    函数的2个参数,第一个表示数据长度,第二个参数表示小数点后位数

select   cast(round(10,2)   as   numeric(5,2)) 结果10.00

select   cast(round(8.672,2)   as   numeric(5,2))  结果:8.67

select   cast(round(8123234.5255,2)   as   numeric(5,2)) 结果:报错 ,超出numeric设定的位数了,所以numeric()第一个参数可以适当大些

猜你喜欢

转载自www.cnblogs.com/wxlhyg/p/9045194.html
今日推荐