数据精度问题:很简单的问题!!!!救命!马上揭贴

whw502 2004-12-21 12:34:34
数据精度问题:
create table #ls_table
(sale_value decimal(20,2) default 0 not null,
product_sale_quantity float default 0 not null,
product_sales_price decimal(20,6) default(0) not null)
insert #ls_table
select 290598.29,20000.0,0
select convert(decimal(30,6),(convert(decimal(20,2),sale_value)/product_sale_quantity)) from #ls_table
drop table #ls_table
应为14.529915
14.529914
怎样使它变为14.529915
谢谢!!先

...全文
153 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
haohaolau 2004-12-21
  • 打赏
  • 举报
回复
试过,这样就可以了:
create table #ls_table
(sale_value decimal(20,2) default 0 not null,
product_sale_quantity float default 0 not null,
product_sales_price decimal(20,6) default(0) not null)
insert #ls_table
select 290598.29,20000.0,0
select convert(decimal(30,6),ROUND((convert(decimal(20,2),sale_value)/product_sale_quantity),7)) from #ls_table
drop table #ls_table
GO

didoleo 2004-12-21
  • 打赏
  • 举报
回复
(decimal(30,7) 就可以了
didoleo 2004-12-21
  • 打赏
  • 举报
回复
convert(decimal(30,6),(convert(decimal(20,2),sale_value)/product_sale_quantity)) ->
convert(decimal(30,7),(convert(decimal(20,2),sale_value)/product_sale_quantity))
NinGoo 2004-12-21
  • 打赏
  • 举报
回复
ROUND
返回数字表达式并四舍五入为指定的长度或精度。

语法
ROUND ( numeric_expression , length [ , function ] )

参数
numeric_expression

精确数字或近似数字数据类型类别的表达式(bit 数据类型除外)。

length

是 numeric_expression 将要四舍五入的精度。length 必须是 tinyint、smallint 或int。当 length 为正数时,numeric_expression 四舍五入为 length 所指定的小数位数。当 length 为负数时,numeric_expression 则按 length 所指定的在小数点的左边四舍五入。

function

是要执行的操作类型。function 必须是 tinyint、smallint 或 int。如果省略 function 或 function 的值为 0(默认),numeric_expression 将四舍五入。当指定 0 以外的值时,将截断 numeric_expression。

返回类型
返回与 numeric_expression 相同的类型。

注释
ROUND 始终返回一个值。如果 length 是负数且大于小数点前的数字个数,ROUND 将返回 0。
NinGoo 2004-12-21
  • 打赏
  • 举报
回复
create table #ls_table
(sale_value decimal(20,2) default 0 not null,
product_sale_quantity float default 0 not null,
product_sales_price decimal(20,6) default(0) not null)
insert #ls_table
select 290598.29,20000.0,0
select convert(decimal(30,6),round( convert(decimal(20,2),sale_value)/product_sale_quantity,7)) from #ls_table
drop table #ls_table
子陌红尘 2004-12-21
  • 打赏
  • 举报
回复
select convert(decimal(30,6),round(convert(decimal(30,7),(convert(decimal(20,2),sale_value)/product_sale_quantity)),6)) from #ls_table
火山企鹅 2004-12-21
  • 打赏
  • 举报
回复
create table #ls_table
(sale_value decimal(20,2) default 0 not null,
product_sale_quantity float default 0 not null,
product_sales_price decimal(20,6) default(0) not null)
insert #ls_table
select 290598.29,20000.0,0
select convert(decimal(30,6),(convert(decimal(20,1),sale_value)/product_sale_quantity)) from #ls_table
whw502 2004-12-21
  • 打赏
  • 举报
回复
没人知道吗!?!?!
whw502 2004-12-21
  • 打赏
  • 举报
回复
to:haohaolau(haohaolau)
为什么是先round (@whw,7)然后再convert(decimal(30,6)),@whw)
难道decimal不能四舍五入吗!!???

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧