相关疑难解决方法(0)

SQL Server舍入错误,给出不同的值

我有一个存储过程,需要进行大量计算,并将结果存储在几个临时表中。最后计算总和并四舍五入到小数点后两位并存储在临时表中并选择该表。

所有中间和最终临时表的关注列的数据类型均为float。

原始方案:

Declare @Intermediate table
{
 --several other columns

Labor float

--several other columns
};

---Lots of calculation ---xx-----

Declare @Final table
{
 --several other columns

LaborTotal float

--several other columns
};

INSERT INTO @Final  SELECT ROUND(ISNULL((SELECT SUM([Labor]) FROM @Intermediate ),0),2)  AS LaborTotal;

SELECT * FROM @Final;

Result: 7585.22  --> when rounded  //Here is the error Expecting 7585.23
        7585.225 --> when not rounded
Run Code Online (Sandbox Code Playgroud)

测试用例 :

   DECLARE @test float = 7585.225;
   SELECT ROUND(@test,2) AS Result; --> results 7585.23

   SELECT ROUND(7585.225,2) …
Run Code Online (Sandbox Code Playgroud)

sql sql-server azure-sql-database

3
推荐指数
1
解决办法
9552
查看次数

标签 统计

azure-sql-database ×1

sql ×1

sql-server ×1