当前位置: 代码迷 >> Sql Server >> 存储过程中参数中小数的的精度有关问题!
  详细解决方案

存储过程中参数中小数的的精度有关问题!

热度:274   发布时间:2016-04-27 21:55:55.0
存储过程中参数中小数的的精度问题!!
我的存储过程是这样的:
ALTER   PROCEDURE   pr_updateBill
(@billid   int,@days   decimal,@medicalfee   decimal(18,2),@others   decimal,@comment   nvarchar(200))
AS
update   dt_bill   set   [email protected],[email protected],[email protected],[email protected]   where   [email protected]
RETURN  

现在出现奇怪的现象
当我用
@medicalfee
@others
用值6.5修改时
数据库中存储的是
7.00
字段medicalfee
在数据库中存储格式是decimal(18,2)

请大侠指点,谢谢。


------解决方案--------------------
decimal(p,s)

p(精度)

指定小数点左边和右边可以存储的十进制数字的最大个数。精度必须是从 1 到最大精度之间的值。最大精度为 38。

s(小数位数)

指定小数点右边可以存储的十进制数字的最大个数。小数位数必须是从 0 到 p 之间的值。默认小数位数是 0


取决于你数据表定义的字段medicalfee和others,是什么类型,
具体地说就是如果是decimal的话,看你精确到小数点多少位,默认是0。
所以会四舍五入,6.5——> 7
------解决方案--------------------
试验了一下,没有问题啊

create table temp
(num1 decimal(18,2),num2 decimal)

insert into temp
select 7,7


update temp set num1=6.5,num2=6.5


select * from temp
-----------
num1 num2
6.50 7

------解决方案--------------------
select 2/3--结果为0
select 2.0/3--结果为.666666
楼主明白没,在你传参时的数字类型决定了结果.

------解决方案--------------------
如下列子:
declare @i decimal(15,2),@j numeric(15)
select @i=6.5
select @[email protected]
select @j

-----------------
7

(所影响的行数为 1 行)
  相关解决方案