简体   繁体   English

在SQL Server 2008 R2中取整

[英]Rounding in sql server 2008 R2

I have this query 我有这个查询

(case when a.item_no >= '77000' and a.item_no <='77099' then
    (op_drill + op_machine + op_ssd + op_freight + op_paint + ((actual_tooling * 1.2))) 
    else (op_drill + op_machine + op_ssd + ((op_drill + op_machine + op_ssd) *.27) + ((op_drill + op_machine + op_ssd + op_freight + (op_curforg *1.25) + ((op_drill + op_machine + op_ssd)*.27)) * .075)+
     op_freight + (op_curforg *1.25) + op_paint) 
      end)  as new_cost,

it returns 10.1201575 它返回10.1201575

In vb.net I can run this statement 在vb.net中,我可以运行以下语句

 dblNewCost = Math.Round(dblNewCost, 2, MidpointRounding.AwayFromZero)

which returns 10.13 返回10.13

Is there a way to duplicate this is sql server. 有没有办法复制这是SQL Server。 I tried round(num,2) but that didn't showup correctly 我尝试了round(num,2),但未正确显示

I think you have some other issue. 我认为您还有其他问题。 SQL Servers ROUND() function works just like VB's. SQL Server ROUND()函数的功能与VB的功能相同。 There is no way using Math.Round(10.1201575, 2, MidpointRounding.AwayFromZero) would return 10.13. 无法使用Math.Round(10.1201575, 2, MidpointRounding.AwayFromZero)返回10.13。 Compare the number that is being rounded on both side to make sure you are comparing apples-to-apples. 比较双方的四舍五入数字,以确保您比较的是苹果与苹果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM